Kenneth Roy Cabrera Torres
2010-Sep-14 16:34 UTC
[R] Problems with "pdf" device using "plot" "glht" function on "multcomp" library.
Hi R users: I have de following data frame (called "Sx") Descripcion Nitratos Cont85g 72.40 Cont85g 100.50 Cont85g 138.30 Cont80g 178.33 Cont80g 79.01 Cont80g 74.16 Cont75g 23.70 Cont75g 15.80 Cont75g 16.20 Patron80g 88.93 Patron80g 113.01 Patron80g 86.53 If I run this code without the "pdf" device it works fine on the screen, but when I use the "pdf" device it does not show in the "plot1.pdf" file what I got on the screen. What am I doing wrong? Thank you for your help. library(multcomp) Sx<-data.frame(Descripcion factor(c("Cont85g","Cont85g","Cont85g", "Cont80g","Cont80g","Cont80g", "Cont75g","Cont75g","Cont75g", "Patron80g","Patron80g","Patron80g")), Nitratos=c(72.40,100.50, 138.30, 178.33,79.01,74.16, 23.70, 15.80,16.20, 88.93,113.01,86.53)) pdf("plot1.pdf") m1<-aov(Nitratos~Descripcion-1,data=Sx) vect1<-table(Sx$Descripcion) K<-contrMat(vect1,base=4) dnk<-glht(m1,linfct=K) summary(dnk) old.par<-par(no.readonly = TRUE) par(mai=c(1,2,1.25,1),mgp=c(3,1,0)) print(plot(dnk,las=1,xlab="")) print(abline(v=0,lty=2)) par(old.par) dev.off()
Kenneth Roy Cabrera Torres
2010-Sep-14 16:43 UTC
[R] Problems with "pdf" device using "plot" "glht" function on "multcomp" library.
Thank you Jorge Iv?n: Im working on a Linux platform, and with a recent pathed version of R. Does it work on windows? R version 2.11.1 Patched (2010-09-10 r52887) Platform: x86_64-unknown-linux-gnu (64-bit) locale: [1] LC_CTYPE=es_CO.UTF-8 LC_NUMERIC=C LC_TIME=es_CO.UTF-8 LC_COLLATE=es_CO.UTF-8 LC_MONETARY=es_CO.UTF-8 [6] LC_MESSAGES=es_CO.UTF-8 LC_PAPER=es_CO.UTF-8 LC_NAME=es_CO.UTF-8 LC_ADDRESS=es_CO.UTF-8 LC_TELEPHONE=es_CO.UTF-8 [11] LC_MEASUREMENT=es_CO.UTF-8 LC_IDENTIFICATION=es_CO.UTF-8 attached base packages: [1] splines stats graphics grDevices utils datasets methods base other attached packages: [1] multcomp_1.2-0 survival_2.35-8 mvtnorm_0.9-92 RColorBrewer_1.0-2 lattice_0.19-11 rkward_0.5.3 loaded via a namespace (and not attached): [1] grid_2.11.1 tools_2.11.1 El mar, 14-09-2010 a las 12:37 -0400, Jorge Ivan Velez escribi?:> Hola Kenneth, > > > Acabo de correrlo en un Mac y funciona bien. Cual es tu sessionInfo()? > > > Saludos, > Jorge > > > > sessionInfo() > R version 2.11.1 Patched (2010-05-31 r52180) > x86_64-apple-darwin9.8.0 > > > locale: > [1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8 > > > attached base packages: > [1] splines stats graphics grDevices utils datasets > methods base > > > other attached packages: > [1] multcomp_1.2-0 survival_2.35-8 mvtnorm_0.9-92 seqinr_3.0-0 > MuMIn_0.13.14 > > > loaded via a namespace (and not attached): > [1] tools_2.11.1 > > > > > On Tue, Sep 14, 2010 at 12:34 PM, Kenneth Roy Cabrera Torres > <krcabrer at une.net.co> wrote: > Hi R users: > > I have de following data frame (called "Sx") > > Descripcion Nitratos > Cont85g 72.40 > Cont85g 100.50 > Cont85g 138.30 > Cont80g 178.33 > Cont80g 79.01 > Cont80g 74.16 > Cont75g 23.70 > Cont75g 15.80 > Cont75g 16.20 > Patron80g 88.93 > Patron80g 113.01 > Patron80g 86.53 > > If I run this code without the "pdf" device > it works fine on the screen, but when I > use the "pdf" device it does not show in > the "plot1.pdf" file what I got on the screen. > > What am I doing wrong? > > Thank you for your help. > > library(multcomp) > > Sx<-data.frame(Descripcion> factor(c("Cont85g","Cont85g","Cont85g", > "Cont80g","Cont80g","Cont80g", > "Cont75g","Cont75g","Cont75g", > "Patron80g","Patron80g","Patron80g")), > Nitratos=c(72.40,100.50, 138.30, > 178.33,79.01,74.16, > 23.70, 15.80,16.20, > 88.93,113.01,86.53)) > pdf("plot1.pdf") > m1<-aov(Nitratos~Descripcion-1,data=Sx) > vect1<-table(Sx$Descripcion) > K<-contrMat(vect1,base=4) > dnk<-glht(m1,linfct=K) > summary(dnk) > > old.par<-par(no.readonly = TRUE) > par(mai=c(1,2,1.25,1),mgp=c(3,1,0)) > print(plot(dnk,las=1,xlab="")) > print(abline(v=0,lty=2)) > par(old.par) > > dev.off() > > ______________________________________________ > R-help at 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. > >
Kenneth Roy Cabrera Torres
2010-Sep-15 02:40 UTC
[R] Partialy SOLVED Re: Problems with "pdf" device using "plot" "glht" function on "multcomp" library.
Hi R users: I found a workaround for the problem I posted today. I simple use "Cairo" library, then I use CairoPDF() function, and it works!!! The reason maybe is the acrobat reader, because the "okular" reader from Ubuntu Linux shows the graphics just right. Thank you for your help and advice. Kenneth El mar, 14-09-2010 a las 12:37 -0400, Jorge Ivan Velez escribi?:> Hola Kenneth, > > > Acabo de correrlo en un Mac y funciona bien. Cual es tu sessionInfo()? > > > Saludos, > Jorge > > > > sessionInfo() > R version 2.11.1 Patched (2010-05-31 r52180) > x86_64-apple-darwin9.8.0 > > > locale: > [1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8 > > > attached base packages: > [1] splines stats graphics grDevices utils datasets > methods base > > > other attached packages: > [1] multcomp_1.2-0 survival_2.35-8 mvtnorm_0.9-92 seqinr_3.0-0 > MuMIn_0.13.14 > > > loaded via a namespace (and not attached): > [1] tools_2.11.1 > > > > > On Tue, Sep 14, 2010 at 12:34 PM, Kenneth Roy Cabrera Torres > <krcabrer at une.net.co> wrote: > Hi R users: > > I have de following data frame (called "Sx") > > Descripcion Nitratos > Cont85g 72.40 > Cont85g 100.50 > Cont85g 138.30 > Cont80g 178.33 > Cont80g 79.01 > Cont80g 74.16 > Cont75g 23.70 > Cont75g 15.80 > Cont75g 16.20 > Patron80g 88.93 > Patron80g 113.01 > Patron80g 86.53 > > If I run this code without the "pdf" device > it works fine on the screen, but when I > use the "pdf" device it does not show in > the "plot1.pdf" file what I got on the screen. > > What am I doing wrong? > > Thank you for your help. > > library(multcomp) > > Sx<-data.frame(Descripcion> factor(c("Cont85g","Cont85g","Cont85g", > "Cont80g","Cont80g","Cont80g", > "Cont75g","Cont75g","Cont75g", > "Patron80g","Patron80g","Patron80g")), > Nitratos=c(72.40,100.50, 138.30, > 178.33,79.01,74.16, > 23.70, 15.80,16.20, > 88.93,113.01,86.53)) > pdf("plot1.pdf") > m1<-aov(Nitratos~Descripcion-1,data=Sx) > vect1<-table(Sx$Descripcion) > K<-contrMat(vect1,base=4) > dnk<-glht(m1,linfct=K) > summary(dnk) > > old.par<-par(no.readonly = TRUE) > par(mai=c(1,2,1.25,1),mgp=c(3,1,0)) > print(plot(dnk,las=1,xlab="")) > print(abline(v=0,lty=2)) > par(old.par) > > dev.off() > > ______________________________________________ > R-help at 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. > >
Torsten Hothorn
2010-Sep-15 07:42 UTC
[R] Problems with "pdf" device using "plot" "glht" function on "multcomp" library.
Dear Ken, it works for me on Linux. However, the print() commands around plot() are not necessary. Torsten
Paul Johnson
2010-Sep-18 22:28 UTC
[R] Problems with "pdf" device using "plot" "glht" function on "multcomp" library.
Hi, Kenneth It is not clear if you mean that your pdf output usually works, but it does not in this special case, or that this is a first effort with pdf. The answer might depend on which is the case case. If you are just getting started, can I refer you to some lecture notes I made about saving graphs in R? http://pj.freefaculty.org/R/SummerCamp2010/PJ-Lectures/plotting2.pdf If you cut off the file name at the end, you will see the list of the other lectures I prepared for our university's "Summer Stats Camp" in 2010. If pdf does usually work, Could I suggest you take this code and rearrange? Where you have this: pdf("plot1.pdf") m1<-aov(Nitratos~Descripcion-1,data=Sx) vect1<-table(Sx$Descripcion) K<-contrMat(vect1,base=4) dnk<-glht(m1,linfct=K) summary(dnk) old.par<-par(no.readonly = TRUE) par(mai=c(1,2,1.25,1),mgp=c(3,1,0)) print(plot(dnk,las=1,xlab="")) print(abline(v=0,lty=2)) par(old.par) dev.off() Instead, separate the "stats" part from the plot part m1 <- aov(Nitratos~Descripcion-1, data=Sx) vect1 <- table(Sx$Descripcion) K <- contrMat(vect1, base=4) dnk <- glht(m1, linfct=K) summary(dnk) pdf("plot1.pdf", onefile=F, paper="special", height=6, width=6) ### old.par<-par(no.readonly = TRUE) par(mai = c(1, 2, 1.25, 1), mgp = c(3,1,0)) plot(dnk, las = 1, xlab = "") abline(v = 0, lty = 2) ####par(old.par) dev.off() I've made changes to cut your "print" statements and moved your pdf command down to "sandwich" the plot commands. I've added some embellishment which I almost guarantee will make your pdf output more useful. (Spaces are inserted around <- and after commas for readability. Check the R examples, they generally recommend that). To the R experts, it may be that the "par" stuff seems obvious, but to the rest of us, well, it is not completely so. You do not need to save the par values because the par setting you change is instantly forgotten when you do dev.off(). So you don't need to worry about saving the default settings and then returning them. Run par() to see for yourself after dev.off(). par's defaults will be back where they were at the beginning. You would only need to do "remember my par" thing if you were trying to put several graphs into a single output device, which you aren't. And I've made that clear by putting onefile=F in the pdf statement. I'd try it without the "par" at all if there is still trouble in the output file. I added the paper="special" option in the pdf command in order to make the margins in the output more reasonable. If you don't do that, the pdf output assumes you are wanting a whole sheet of paper, so there will be some massive margins in your output. Good luck. -- Paul E. Johnson Professor, Political Science 1541 Lilac Lane, Room 504 University of Kansas