简体   繁体   English

在 ggiraph 0.7 (R) 中设置工具提示字体

[英]Setting tooltip font in ggiraph 0.7 (R)

This may well be a CSS query rather than a {ggiraph} question, or may be to do with my R or Cairo installation, but here goes:这很可能是一个 CSS 查询而不是 {ggiraph} 问题,或者可能与我的 R 或 Cairo 安装有关,但这里是:

I'm building a ggiraph interactive plot, but the settings that I apply for tooltip options aren't applied to the printed plot.我正在构建一个 ggiraph 交互式 plot,但我为工具提示选项应用的设置并未应用于打印的 plot。

This is a reprex:这是一个代表:

library(tidyverse)
library(ggiraph)
test_df <- tibble::tribble(
  ~Index, ~This, ~That, ~Something.Else,
      1L,   20L,   57L,             "A",
      2L,   22L,   58L,             "B",
      3L,   24L,   65L,             "B",
      4L,   26L,   68L,             "A",
      5L,   28L,   89L,             "B",
      6L,   30L,   93L,             "B",
      7L,   32L,   97L,             "B",
      8L,   34L,  101L,             "A",
      9L,   36L,  105L,             "B",
     10L,   38L,  109L,             "B",
     11L,   40L,   72L,             "A",
     12L,   42L,   76L,             "B",
     13L,   44L,   80L,             "B",
     14L,   46L,   84L,             "A"
  )

plot <- ggplot(test_df, aes(x = This, y= That, colour = Something.Else))+
  geom_point_interactive(alpha = 0.8, aes(tooltip = That, data_id= Index))
 

tooltip_css <- "background-colour:transparent;font-family: Arial, Helvetica, sans-serif;"
ploti <- girafe(ggobj = plot, fonts = list(sans = "Helvetica"),
                options = c(opts_sizing(width = 0.7)), opts_tooltip(css = tooltip_css))

print(ploti)

You can see the interactive results here: https://rpubs.com/arf/718801你可以在这里看到互动结果: https://rpubs.com/arf/718801

But the issue I have is that despite setting font-family to a sans-serif font, the tooltips are using a different font, plus the background-colour setting is ignored.但我遇到的问题是,尽管将 font-family 设置为 sans-serif 字体,但工具提示使用的是不同的字体,而且背景颜色设置被忽略。 What am I doing wrong?我究竟做错了什么?

工具提示字体和背景示例 Background: I'm using RStudio 1.4.1103背景:我正在使用 RStudio 1.4.1103

R.version _ R.版本_
platform x86_64-apple-darwin17.0平台 x86_64-apple-darwin17.0
arch x86_64拱 x86_64
os darwin17.0操作系统darwin17.0
system x86_64, darwin17.0系统 x86_64,darwin17.0
status状态
major 4专业 4
minor 0.2小 0.2
year 2020 2020年
month 06 06月
day 22第22天
svn rev 78730 svn 转 78730
language R语言 R
version.string R version 4.0.2 (2020-06-22) nickname Taking Off Again version.string R version 4.0.2 (2020-06-22) 昵称 再次起飞

You need to put opts_tooltip in the list for options (see https://davidgohel.github.io/ggiraph/articles/offcran/customizing.html#tooltip-style ):您需要将opts_tooltip放在options列表中(参见https://davidgohel.github.io/ggiraph/articles/offcran/customizing.html#tooltip-style ):

ploti <- girafe(ggobj = plot, fonts = list(sans = "Helvetica"),
                options = list(
                  opts_sizing(width = 0.7), 
                  opts_tooltip(css = tooltip_css)
                )
              )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM