Suppose I have four plots after I faceted my main plot. I want to draw a vertical line on x = 1 in first facet, x = 2 in second facet, x = 3 in third facet and x = 4 in forth facet. How can I do that?
Asked
Active
Viewed 21 times
0
-
1Does this answer your question? https://stackoverflow.com/questions/44196384/how-to-produce-different-geom-vline-in-different-facets-in-r – Jon Spring Mar 15 '22 at 06:54
-
library(tidyverse) dataLine <- mpg %>% group_by(trans) %>% summarize(mean_x = mean(cty)) ggplot(mpg) + aes(x = cty, y = hwy) + facet_wrap(facets = vars(trans)) + geom_point() + geom_vline(data = dataLine, aes(xintercept = mean_x, colour = trans)) – Rfanatic Mar 15 '22 at 09:09