Consider the following example:
require(ggplot2)
aa <- data.frame(date = runif(3,1,100),Change = runif(3,1,100))
bb <- data.frame(date = runif(3,1,100),Change = runif(3,1,100))
dd <- rbind(aa,bb)
dd$site <- c("aa","aa","aa","bb","bb","bb")
Is it possible to produce 2 figures in the same document where figure 1 should be those sites that correspond to sites == 'aa' and the second figure should be those sites that correspond to sites == 'bb'?
I have tried to generate the figures within a loop but nothing seems to be plotted in the pdf:
nams <- ("aa","bb")
pdf("plots.pdf",width = 6,height = 6, paper='A4',family = "Times")
for (i in 1:2){
dd2 <- dd[dd$site == nams[i],]
ggplot(dd,aes(date,Change)) +
geom_line()
}
dev.off()