Change color of median bar in geom_lv()

Viewed 234

Consider the following code:

library(ggplot2); library(dplyr); library(lvplot)
diamonds %>%
  filter(cut == "Good") %>%
  ggplot(aes(x = cut, y=price, fill=color)) + 
  geom_lv(color='black', size=0.75)

which produces the following plot:

boxenplot aka letter-value plot of diamonds dataset

If you look at the bar that represents the median, it is of the same color as the fill color, and therefore hard to distinguish. How would you make it stand out more? (making it black, drawing borders around the median line...?)

1 Answers

While typing the question I realized that reducing the alpha a bit makes the fill color fainter and improves the contrast with the median line.

enter image description here

I hope someone out there finds it useful, but I am still not entirely happy with the result. The line tends to fade in larger plots and is still sub-optimal, so a better solution would be greatly appreciated.

EDIT: I found a trick using boxplots. Boxenplots (or letter-value plots) are an extension of boxplots that include smaller boxes for more percentiles, but they are identical to boxplots between the 25th and 75th percentiles. So what I did was plotting a boxplot on top, setting the fill value to a transparent one, and removing the outliers and whiskers:

diamonds %>%
  filter(cut == "Good") %>%
  ggplot(aes(x = cut, y=price, fill=color)) + 
  geom_lv(color='black', size=0.75) + 
  geom_boxplot(outlier.alpha = 0, coef=0, fill="#00000000")
Related