0

I'm trying to add the median value into the tooltip in geom_boxplot_interactive(tooltip = ), without having to calculate it for each grouping and joining it to the dataset.

I have tried to see if something in stat_summary(), stat or middle would work. But no luck so far.

library(ggplot2) 
library(ggiraph) 
data("mpg") 
# View(mpg) 
p <- ggplot(mpg, aes(x = class, y = hwy, tooltip = class)) + 
  geom_boxplot_interactive() 

ggiraph(code = print(p))
# ggiraph(ggobj = p  + geom_boxplot_interactive(aes(tooltip = data$median)) 

p <- ggplot(mpg, aes(x = drv, y = hwy, tooltip = class, fill = class)) +
  geom_boxplot_interactive(outlier.colour = "red") + 
  guides(fill = "none") + theme_minimal()

girafe(ggobj = p)

This works if I have the median value for each group in the dataset, but I am trying to avoid this if possible.

bbiasi
  • 1,549
  • 2
  • 15
  • 31
Bikash Deb
  • 55
  • 1
  • 7
  • Per R tag: Use `dput()` for data and specify all non-base packages with `library()` calls. – Parfait May 06 '19 at 18:41
  • @Parfait, `data("mpg")`, from `ggplot2`. – bbiasi May 06 '19 at 18:45
  • Please edit your question and avoid unreadable, large code blocks in comments. Please delete comments afterwards. – Parfait May 06 '19 at 18:53
  • @bikash-dep why don't you want to calculate it? You won't be able to display the median in the tooltip if you do not calculate it first – David Gohel May 07 '19 at 05:37
  • As there are many percentiles to calculate for different columns, I was looking for a neater solution where I didn't have to do this beforehand. I've implemented calculation beforehand now. Thanks – Bikash Deb May 07 '19 at 10:16

0 Answers0