[R] multiple graphs with a single legend and trellis graph

John Kane jrkrideau at inbox.com
Thu Jul 9 00:15:45 CEST 2015


Hi Rosa,
Neither the graph nor the data arrived.  R-help can be very fussy about what attached files it will accept. Usually pdf, txt and png, I think, will come through.

In any case it is much better to supply data using the dput() function See ?dput or have a look at http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example and http://adv-r.had.co.nz/Reproducibility.html for how to do this.

It is best to use dput() rather than supplying a data file because dput() ensures that we get an exact copy of the data as it exists on your computer.  There is no real guarantee that I will read in a data file the same way as you have.



John Kane
Kingston ON Canada


> -----Original Message-----
> From: rosita21 at gmail.com
> Sent: Wed, 8 Jul 2015 13:11:34 +0100
> To: djmuser at gmail.com, drjimlemon at gmail.com, r-help at r-project.org
> Subject: Re: [R] multiple graphs with a single legend and trellis graph
> 
> Dear Jim,
> 
> first of all, thank you very much :)
> when I run the code:
> 
> myDF <- rbind(mse.alpha1, mse.alpha2)  # assumes both data frames have
> the same variables in the same order
> 
> 
> myDF$ID <- factor(rep(c("alpha1", "alpha2"), times =
> c(nrow(mse.alpha1), nrow(mse.alpha2))) )
> 
> 
> library(reshape2)
> myDF.melt <- melt(myDF, id = c("ID", "nsample", "lambda"), measure =
> c("mse.naive", "mse.RegCal", "mse.PL"))  #Melt the three columns to be
> plotted, something like
> 
> library(ggplot2)
> ggplot(myDF.melt, aes(x = lambda, y = value, color = variable)) +
>    geom_point() + geom_line() +
>    facet_grid(ID ~ nsample) +
>    labs(x = expression(paste(lambda)), y = "MSE", color = "Type”)
> 
> 
> 
>  I get the attached graph. I also attach my data, so you can see :)
> 
> I’m I able to resize the graphs differently? I.e. for alpha1:
> ylim=ylim=c(0,.6) and for alpha2: ylim=c(0,.17)?
> I reshaped, a new variable in sample was created, NA, Was it me that made
> something wrong?
> 
> I’m very naive and new in R :(
> 
> Thanks again ;)
> 
> 
> 
> 
> 
> 
> 
> Atenciosamente,
> Rosa Oliveira
> 
> --
> ____________________________________________________________________________
> 
> 
> Rosa Celeste dos Santos Oliveira,
> 
> E-mail: rosita21 at gmail.com
> Tlm: +351 939355143
> Linkedin: https://pt.linkedin.com/in/rosacsoliveira
> ____________________________________________________________________________
> "Many admire, few know"
> Hippocrates
> 
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

____________________________________________________________
FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop!



More information about the R-help mailing list