Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
339 views
in Technique[技术] by (71.8m points)

css - 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:

I'm building a ggiraph interactive plot, but the settings that I apply for tooltip options aren't applied to the printed 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

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. What am I doing wrong?

Example of tooltip font and background Background: I'm using RStudio 1.4.1103

R.version _
platform x86_64-apple-darwin17.0
arch x86_64
os darwin17.0
system x86_64, darwin17.0
status
major 4
minor 0.2
year 2020
month 06
day 22
svn rev 78730
language R
version.string R version 4.0.2 (2020-06-22) nickname Taking Off Again

question from:https://stackoverflow.com/questions/65952091/setting-tooltip-font-in-ggiraph-0-7-r

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You need to put opts_tooltip in the list for options (see 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)
                )
              )

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...