Hie,
I am trying to insert geom_vlines in my distributions using specific values. I was able to write the code is as below using the iris
data, but get all the lines plotted on each distribution instead of one line for each.
irismean<-data.frame(z=c(5,5.8,6.3),Species=c("setosa","versicolor","virginica"))
ggplot(iris, aes(Sepal.Length)) +
geom_density_ridges(alpha = 0.1,fill="red",colour="red") +
facet_wrap(~Species) + xlim(0, 10)+
geom_vline(aes(xintercept=z),irismean)
If I use facet_wrap
it works to plot a line on each facet as below,
irismean<-data.frame(z=c(5,5.8,6.3),Species=c("setosa","versicolor","virginica"))
ggplot(iris, aes(Sepal.Length)) +
geom_density(alpha = 0.1,fill="red",colour="red") +
facet_wrap(~Species) + xlim(0, 10)+
geom_vline(aes(xintercept=z),irismean)
I am comparing the same samples, as such the distributions get stacked on top of each other so it would be easier to visually see the differences if I could plot the lines in density ridges
as compared to facet_wrap
furthermore, I would like to add lables to these lines and have tried the code below but keep getting the error (also shown)
library(ggrepel)
irismean<-data.frame(z=c(5,5.8,6.3),Species=c("setosa","versicolor","virginica"))
ggplot(iris, aes(Sepal.Length)) +
geom_density(alpha = 0.1,fill="red",colour="red") +
facet_wrap(~Species) + xlim(0, 10)+
geom_vline(aes(xintercept=z),irismean)+
geom_text_repel(data=iris,mapping=aes(x=Sepal.Length,y=Species,
+ label =paste(irismean),"cm",sep=""))
Warning: Ignoring unknown aesthetics: , sep
Error: Aesthetics must be either length 1 or the same as the data (150): label
Does anyone have suggestions on dealing with this?