I wrote a ggplot as a function of a column (Especies) so I can do all plots at once. But I would like to include the values of the column (i.e. the species name) as the title for each of the generated plots. Anyone knows how?
A sample of the data with two species:
f.spmonth<-structure(list(Ciudad = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("BARCELONA", "MADRID"), class = "factor"), Mes = c(3L, 4L, 5L, 6L, 7L, 8L, 3L, 4L, 5L, 6L, 7L, 8L, 3L, 4L, 5L, 6L, 7L, 8L, 3L, 4L, 5L, 6L, 7L, 8L), Especie = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("Anthocharis cardamines", "Aporia crataegi"), class = "factor"), Número = c(10, 1, 10, 20, 5, 0, 1, 3, 12, 22, 12, 0, 4, 45, 23, 12, 20, 30, 20, 11, 10, 20, 5, 0)), row.names = c(NA, 24L), class = "data.frame")
My code:
hist.fenologias<-function(f.spmonth){
ggplot(data =f.spmonth, aes(x = Mes,y= Número,fill= Ciudad)) +
geom_area(stat="identity", show.legend = FALSE)+ theme_bw()+
labs(y = "Número de individuos observadas", x ="Mes") +
facet_wrap(~ Ciudad, nrow = 2,scale="free_y")}
all.fenologias<-dlply(f.spmonth , c("Especie") , function(x) plot(hist.fenologias(x) ) )
Many thanks in advance!