r - How to draw transparent lines in ggplot2 -


i want hide elements in ggplot2 facets depending on given variable. first idea switch elements transparent, not disappear plot (see image below).

for label value less 1 dont want plot segment , text.

library(tidyverse) library(ggplot2)  cardata <- mtcars # max each gear facet df2 <- cardata %>% group_by(gear) %>%   summarise(ypos = max(mpg)*1.1) %>%   mutate(x = 1, xend = 2) # use factor level locators df2$trans <- c(0,0,1) df2$label <- c(0.1,0.1,3)  cardata$cyl <- factor(cardata$cyl)  p <- ggplot(cardata, aes(cyl, mpg)) +   geom_boxplot() +   geom_segment(data = df2, aes(y = ypos, yend = ypos, x = x, xend = xend,alpha=trans)) +   geom_text(data = df2, aes(y = ypos*1.02, x = mean(c(x, xend)),label=label,alpha=trans))+   facet_wrap( ~ gear,ncol=2, scales="free") p 

enter image description here

you there. need override default range alpha scale, c(0.1, 1):

p + scale_alpha(range = c(0, 1)) 

plot


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -