2

Using ggplot2 to plot multiple plots for time series from 25 sites (ID) by group (gp).

df3[1:5,]
  year  ID val gp 
1 1985 ID1   5  1
2 1986 ID1   5  1
3 1987 ID1  19  1
4 1988 ID1  20  1
5 1989 ID1  21  1

P<- ggplot(df3, aes(as.numeric(year), val, colour=ID)) + 
  geom_line() + 
  facet_wrap(~gp)+ 
  theme(strip.background = element_rect("transparent",colour = NA))+
  theme(strip.text.x = element_text(size = 17, face="bold", colour = "black"))+
  ylab( "Frequency                                  Frequency" ) + 
  xlab("")+
  theme(axis.text=element_text(size=14, face="bold", color = "black"),
        axis.title=element_text(size=17,face="bold"))
P

enter image description here

As you can see it hard to use the legend to know each plot's sites (IDs). Is there a way to add a legend to each panel instead of one legend.

Ali
  • 83
  • 7

0 Answers0