Hi I am trying to understand how to use ggplot2 to plot multiple time-series in one single graphics. In order to do so, I have modified the example given at http://docs.ggplot2.org/current/guide_legend.html to use my own data.
Here is the script so far # Script for plotting all variables rm(list=ls()) graphics.off() ## ---- Q1 ---- library(ggplot2); library(gridExtra) require(timeDate) require(reshape2) ind <- seq(1,1000) modelnames <- c("PRO1_PXXS_F_MODEL_1", "PRO2_PXXS_F_MODEL_2", "PRO3_PXXS_F_MODEL_3", "PRO4_PXXS_F_MODEL_4", "Real_Data") # Create the time vector Time<-as.POSIXct(timeSequence(from="2014-05-09 18:43:00",length.out=length(ind), by="mins")) # Create variable aux=cbind(runif(length(ind),min=2300,max=2700),runif(length(ind),min=3200,max=3700), runif(length(ind),min=2600,max=2800),runif(length(ind),min=2300,max=2400), runif(length(ind),min=2700,max(3300))) resmodMay=data.frame(id=Time,aux); colnames(resmodMay)=c("Time",modelnames); meltdf<-melt(resmodMay, id="Time") ## ---- Q2 ---- # Plot g<-ggplot(meltdf,aes(x=Time,y=value,colour=variable,group=variable)) g<-g+geom_line()+labs(title = "Some plots") g<-g+xlab("Date")+ylab("Value of the variable")+scale_fill_discrete(guide = guide_legend(title = "V")) print(g) ## ---- Q3 ---- # One Solution meltdfm<-melt(resmodMay, id="Time") colnames(meltdfm)[2]<-"Models" g1<-ggplot(meltdfm,aes(x=Time,y=value,colour=Models,group=Models)) g1<-g1+geom_line()+labs(title = "Some plots") g1<-g1+xlab("Date")+ylab("Value of the variable")+scale_fill_discrete(guide = guide_legend(title = "V")) print(g1) On the top of the legends ggplot2 writes "variable"; I need to change that and also need to increase the size of the legends (fonts size, symbols, everything). As you can see I have a solution for the first problem (title of the legend), but that is not the type of solution I want. I was thinking of using ggplot2 layers to change that. Something like that last line on ##---- Q2 -----, which unfortunately it does not work (even though is given as example on ggplot2 documentation - It is likely that I have misread the example). Any help will be most appreciated. Ed [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.