[R] Change plot order in lattice xyplot
Greetings, I am writing with a question regarding plotting using the xyplot command in lattice. I currently have the commands shown below, but I need to produce a plot that orders the Month variable differently. I was told to use the lattice.options command (shown below) to change the plot order, and this helped by starting the plot at a point other than the bottom-left origin, but this did not transpose the plot in the way I need. I need the plot to begin with June, then July, August, September, October, beginning at the top left side of the plot area. Does anyone now how to make this happen? A section of my data and the commands I am currently using are shown below. Thank you for any assistance! Data: Month Log10_echo_integration_dens Log10_trawl_dens June -2.55876 -2.74726 June -2.24346 -3.7015 July -3.14616 -2.83227 July -2.69961 -3.7015 August -2.96135 -3.7015 August -2.29246 -2.29232 September -2.2096 -2.20181 September -1.80488 -1.81614 October -2.28896 -1.84266 October -2.4 -2.35319 #Commands lattice.options(default.args = list(as.table = TRUE)) xyplot(Log10_trawl_dens~Log10_echo_integration_dens | Month, data = (subset(T.A., Net_Type==T)),ylim=c(-4,0),xlim=c(-4,0),xlab=Log density from hydroacoustics (integration),ylab=Log density from Tucker trawl,main=Density estimates, Tucker Trawl, cex=1.5) Best, Paul S. [[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.
Re: [R] Change plot order in lattice xyplot
Prior to creating a plot I usually just order the factor levels to the order I want them in. So for your example I would do: #Create some data library(lattice) x - runif(100, 0, 20) df - data.frame(x) df$y - (1:10) df$Month - c(October, September, August, July,June) #Plot the figure plt -xyplot(x~y | Month, data =df, layout=c(5,1), xlab=Log density from hydroacoustics (integration), ylab=Log density from Tucker trawl, main=Density estimates, Tucker Trawl, cex=1.5) #Factor levels aren't in the order you want them in. Reorder them how you want. df$Month - factor(df$Month, levels=c(June,July,August, September, October), order=TRUE) #Plot again. plt HTH, Sam -- View this message in context: http://r.789695.n4.nabble.com/Change-plot-order-in-lattice-xyplot-tp2531542p2531619.html Sent from the R help mailing list archive at Nabble.com. __ 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.
Re: [R] Change plot order in lattice xyplot
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Sam Albers Sent: Wednesday, September 08, 2010 9:42 AM To: r-help@r-project.org Subject: Re: [R] Change plot order in lattice xyplot Prior to creating a plot I usually just order the factor levels to the order I want them in. So for your example I would do: #Create some data library(lattice) x - runif(100, 0, 20) df - data.frame(x) df$y - (1:10) df$Month - c(October, September, August, July,June) #Plot the figure plt -xyplot(x~y | Month, data =df, layout=c(5,1), xlab=Log density from hydroacoustics (integration), ylab=Log density from Tucker trawl, main=Density estimates, Tucker Trawl, cex=1.5) #Factor levels aren't in the order you want them in. Reorder them how you want. df$Month - factor(df$Month, levels=c(June,July,August, September, October), order=TRUE) You don't need to use the ordered=TRUE argument there and it may be mildly inappropriate. The command factor(theData, levels=theLevels) does not reorder theLevels. Using ordered=TRUE means to make an object of class ordered (a subclass of factor). Modelling functions like lm() deal with ordered factors a bit differently than unordered factors, but the ordered/factor distinction has no effect on how most graphics and data manipulation functions deal with them. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com #Plot again. plt HTH, Sam -- View this message in context: http://r.789695.n4.nabble.com/Change-plot-order-in-lattice-xyp lot-tp2531542p2531619.html Sent from the R help mailing list archive at Nabble.com. __ 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. __ 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.