facet-wrap
facet_wrap add geom_hline
Minimal example using mtcars – you have to create a data frame with mean for each gear (in your case it’s Name). library(tidyverse) dMean <- mtcars %>% group_by(gear) %>% summarise(MN = mean(cyl)) ggplot(mtcars) + geom_point(aes(mpg, cyl)) + geom_hline(data = dMean, aes(yintercept = MN)) + facet_wrap(~ gear) For your case this should work: library(tidyverse) dMean <- … Read more
How to produce different geom_vline in different facets in R?
Here’s how you can put in different geom_vline for different iris species: ggplot(iris, aes(Sepal.Length, Petal.Length)) + facet_wrap(~Species, scales=”free”) + geom_point() + geom_vline(data=filter(iris, Species==”setosa”), aes(xintercept=5), colour=”pink”) + geom_vline(data=filter(iris, Species==”versicolor”), aes(xintercept=6), colour=”blue”) + geom_hline(data=filter(iris, Species==”virginica”), aes(yintercept=6), colour=”green”)
ggplot2: Changing the order of stacks on a bar graph
This might be a solution. What I did was ordering the dataset, so that the value I wanted to appear closest to the x-axis appeared first in the dataset. (I’ve used your ordering of factors here). This fixt the positioning of the bars. Then, we had to change the colors and order of the legend. … Read more
Setting absolute size of facets in ggplot2
I’ve used the following function for this purpose, set_panel_size <- function(p=NULL, g=ggplotGrob(p), file=NULL, margin = unit(1,”mm”), width=unit(4, “cm”), height=unit(4, “cm”)){ panels <- grep(“panel”, g$layout$name) panel_index_w<- unique(g$layout$l[panels]) panel_index_h<- unique(g$layout$t[panels]) nw <- length(panel_index_w) nh <- length(panel_index_h) if(getRversion() < “3.3.0”){ # the following conversion is necessary # because there is no `[<-`.unit method # so promoting to unit.list … Read more