0

I would like to add an average line to each of my facet plot (specific to each species & variable), but only managed to plot the facets without the line. I've attached a sample of the data as well if you'd like to try.

data_tidy = data %>%
  group_by(species) %>%
  gather(variable, value, duration, voiced, ampl_median, ampl_sd, amplVoiced_mean, 
  amplVoiced_median) %>% 
  dplyr::select(species,variable,value) 

ggplot(data_tidy,aes(x=value,y=..scaled..,fill=variable))+
  geom_density()+
  facet_grid(species~variable,scales="free")+
  geom_vline(data=data_tidy, aes(xintercept=mean(value)), colour="grey50")

Screenshot of attempt (without average line)

Sample data available at: https://drive.google.com/open?id=1u_6u6bXMfdut91bhAFIACHIt5CCGaMl2

Thanks in advance.

pogibas
  • 27,303
  • 19
  • 84
  • 117
Grace
  • 201
  • 2
  • 13
  • foremost a reproducible question attracts more attention. See [here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) to learn how to create one. Second, have you seen this [page](http://www.sthda.com/english/wiki/ggplot2-density-plot-quick-start-guide-r-software-and-data-visualization), if yes and still no solution, then do update your question to reflect the same. – mnm Jun 19 '18 at 08:16
  • Yes I did check that page but the problems are actually different. (Btw, the sample data is in the attachment if you'd like to reproduce the results) But here's sharing the below blog's example that helped and my issue is now resolved, thanks! http://bioinfo.iric.ca/ggplot2-101-easy-visualization-for-easier-analysis/ – Grace Jun 19 '18 at 15:42

0 Answers0