[R] dotplot lattice problems: y axis values and bg color output in jpg
I have a linux system with Fedora Core 2 and R-2.0. I was comparing plots made with plot() and dotplot() and discovered a problem. Although the dots are positioned correctly, the numerical labels in the dotplot y axis are not correct. I put copies here: http://lark.cc.ku.edu/~pauljohn/R/plotTrouble1.jpg That is the correct one from plot, with the higest value on y showing at 18. http://lark.cc.ku.edu/~pauljohn/R/plotTrouble2.jpg That is the dotplot one. The picture is basically the same, except the numbers on the y axis only go up to 8. But the dots are in the correct spots and the x axis is labeled correctly. On the screen, the plots have white backgrounds, but the picture from the dotplot turns out gray. Why is that? Sometimes, if I run another lattice plot in the same session, the colors change to the dark background, and I suppose the same trouble is happening. Isn't trellis.par.set() going to remain in place for all following trellis plots? Here's the code I used to make these 2 graphs. x11(height=6.5,width=6.5) data2003- subset(elaine1,POLCYEAR==2003) plot(data2003$OLDCRASH,data2003$RENUCYC) modall - lm(RENUCYC~OLDCRASH,data=data2003) abline(modall) dev.copy(device=jpeg,file=plotTrouble1.jpg) dev.off() dev.off() trellis.par.set(theme=col.whitebg(),height=9,width=6.5) dotplot (RENUCYC~OLDCRASH, data=elaine1, xlab=ECR, as.table=T,subset=POLCYEAR==2003, panel=function(x,y) { panel.dotplot(x,y,cex=0.2); panel.lmline(x,y); } ) jpeg(file=plotTrouble2.jpg,bg=white,height=480,width=480) trellis.last.object() dev.off() dev.off() I tried to force the ylim on the dotplot up to 18, but it just produced this even uglier result. http://lark.cc.ku.edu/~pauljohn/R/plotTrouble3.jpg -- Paul E. Johnson email: [EMAIL PROTECTED] Dept. of Political Sciencehttp://lark.cc.ku.edu/~pauljohn 1541 Lilac Lane, Rm 504 University of Kansas Office: (785) 864-9086 Lawrence, Kansas 66044-3177 FAX: (785) 864-5700 __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] dotplot lattice problems: y axis values and bg color output in jpg
Paul Johnson wrote: I have a linux system with Fedora Core 2 and R-2.0. I was comparing plots made with plot() and dotplot() and discovered a problem. Although the dots are positioned correctly, the numerical labels in the dotplot y axis are not correct. I put copies here: http://lark.cc.ku.edu/~pauljohn/R/plotTrouble1.jpg That is the correct one from plot, with the higest value on y showing at 18. http://lark.cc.ku.edu/~pauljohn/R/plotTrouble2.jpg That is the dotplot one. The picture is basically the same, except the numbers on the y axis only go up to 8. But the dots are in the correct spots and the x axis is labeled correctly. On the screen, the plots have white backgrounds, but the picture from the dotplot turns out gray. Why is that? Sometimes, if I run another lattice plot in the same session, the colors change to the dark background, and I suppose the same trouble is happening. Isn't trellis.par.set() going to remain in place for all following trellis plots? Here's the code I used to make these 2 graphs. x11(height=6.5,width=6.5) data2003- subset(elaine1,POLCYEAR==2003) plot(data2003$OLDCRASH,data2003$RENUCYC) modall - lm(RENUCYC~OLDCRASH,data=data2003) abline(modall) dev.copy(device=jpeg,file=plotTrouble1.jpg) dev.off() dev.off() trellis.par.set(theme=col.whitebg(),height=9,width=6.5) dotplot (RENUCYC~OLDCRASH, data=elaine1, xlab=ECR, as.table=T,subset=POLCYEAR==2003, panel=function(x,y) { panel.dotplot(x,y,cex=0.2); panel.lmline(x,y); } ) jpeg(file=plotTrouble2.jpg,bg=white,height=480,width=480) trellis.last.object() dev.off() dev.off() I tried to force the ylim on the dotplot up to 18, but it just produced this even uglier result. http://lark.cc.ku.edu/~pauljohn/R/plotTrouble3.jpg Paul, dotplot is not doing what you think it's doing. RENUCYC is being forced to a factor with 9 levels. I think what you intending to use is xyplot. Just trellis.par.set(theme=col.whitebg(),height=9,width=6.5) xyplot(RENUCYC~OLDCRASH, data=elaine1, xlab=ECR, as.table=T,subset=POLCYEAR==2003, panel=function(x,y) { panel.dotplot(x,y,cex=0.2) #; no need for semi-colons panel.lmline(x,y) }) As for your second question, when you call jpeg a new device is called. You need to reset the theme after opening the device, or just use trellis.device: trellis.device(jpeg, file=plotTrouble2.jpg, theme = col.whitebg(),height=480,width=480) trellis.last.object() dev.off() --sundar __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] dotplot lattice problems: y axis values and bg color output in jpg
Hi Paul. * Paul Johnson [EMAIL PROTECTED] [041023 00:24]: *snip* That is the dotplot one. The picture is basically the same, except the numbers on the y axis only go up to 8. But the dots are in the correct spots and the x axis is labeled correctly. Unless RENUCYC is a factor, a dotplot makes little sense. Afaik you're looking for an xyplot. On the screen, the plots have white backgrounds, but the picture from the dotplot turns out gray. Why is that? It's the default lattice color sheme which makes for easier viewing on computer screens. Sometimes, if I run another lattice plot in the same session, the colors change to the dark background, and I suppose the same trouble is happening. Isn't trellis.par.set() going to remain in place for all following trellis plots? To quote the manual: Once a device is open, it's settings can be modified. When another instance of the same device is opened later using trellis.device, the settings for that device are reset to its defaults, unless otherwise specified in the call to trellis.device. HTH Olaf __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] dotplot lattice problems: y axis values and bg color output in jpg
On Friday 22 October 2004 17:16, Paul Johnson wrote: I have a linux system with Fedora Core 2 and R-2.0. I was comparing plots made with plot() and dotplot() and discovered a problem. Although the dots are positioned correctly, the numerical labels in the dotplot y axis are not correct. That's comparing apples and oranges, sort of. You should use xyplot instead of dotplot if you want the equivalent of plot (more precisely, plot.default). Although it's not obvious from your code, I'll bet your Y variable is numeric with 9 unique values. dotplot treats one of its variables as a factor. If neither variable are factors, it by default chooses the Y variable is a factor. If it is numeric, as in your case, it converts it into a 'shingle' (see ?shingle). This has almost the same effect as coercion to a factor, except the Y values are labeled 1,2,... instead of the levels. I put copies here: http://lark.cc.ku.edu/~pauljohn/R/plotTrouble1.jpg That is the correct one from plot, with the higest value on y showing at 18. http://lark.cc.ku.edu/~pauljohn/R/plotTrouble2.jpg That is the dotplot one. The picture is basically the same, except the numbers on the y axis only go up to 8. But the dots are in the correct spots and the x axis is labeled correctly. They are not the same. The Y-spacing between the unique values are all equal in dotplot, unlike in the plot output. On the screen, the plots have white backgrounds, but the picture from the dotplot turns out gray. Why is that? Sometimes, if I run another lattice plot in the same session, the colors change to the dark background, and I suppose the same trouble is happening. Isn't trellis.par.set() going to remain in place for all following trellis plots? Trellis settings are very much device-specific, and trellis.par.set only affects the currently open device (much like par). You call it to change the x11 settings, but you haven't changed the jpeg settings anywhere, so the defaults are used. What happens for new instances of the same device is a bit more subtle. Once you change settings for a particular device type (say x11), lattice remembers these settings. However, if you open a new instance of this device with, say trellis.device(x11) the x11 settings revert back to the x11 defaults (this behaviour can be suppressed by an argument to trellis.device). Now, even if you don't do this explicitly, any attempt to create a Trellis plot while there's no currently active device results in a call to trellis.device, and hence results in a new instance with the settings reset to defaults. However, the settings are NOT reset if the device is already open. An example to make things a bit less confusing (hopefully): p - xyplot(1~1) x11() p ## default (grey) background trellis.par.set(col.whitebg()) p ## 'white' (actually transparent) background dev.off() x11() p ## still white background, settings retained dev.off() p ## new instance of x11 started, settings reset, ## hence grey background If you find this surprising, it's basically because lattice has no way of knowing that a new device has been opened unless it's done through trellis.device. Otherwise, the idea is to be similar to par and reset the defaults everytime. Deepayan __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html