[R] losing line of mtext when saving to png format

Joshua Wiley jwiley.psych at gmail.com
Sun Jun 13 21:32:43 CEST 2010


Hey John,

I believe this issue is that the png device is different from the
onscreen one.  You set the margins for the on screen with a call to
par() but not for the png().  The code below works for me.

################
mydata  <- data.frame(kel=c(13,253,263,273,283,292,303,313,323,333,573,853),
cent=c( -280, -40, -30, -20, -10, 1, 10, 20, 30, 40, 280, 560))
png("C:/Rjunk/brendengraph.png", width=600, height=600)
par(mar=(c(5, 4, 6, 2))) #this goes after the call to png()
plot(1:12,mydata$kel, main=" ", xlab=" ", ylab=" ",type="l",
col="red", xaxt="n", yaxt="n",cex=.75)
axis(1, at=1:12,labels=as.character(mydata$kel), cex.axis=.75)
axis(3, at=1:12, labels=as.character(mydata$cent), cex.axis=.75)
mtext(side = 1, line=2, text="Degrees Kelvin",cex=.75 )
mtext(side = 3, line=2, text="Degrees Centegrade",cex=.75 )
mtext(side = 3, line=4, text="Room Temperature", font=2, cex=.85)
dev.off()
#################

HTH,

Josh

On Sun, Jun 13, 2010 at 12:09 PM, John Kane <jrkrideau at yahoo.ca> wrote:
>
> I have a simple graph (oode below) which looks fine on the screen but when
> I save it in png format the title (actually the last mtext line) is cut off.
>
> I am pretty sure that I am doing something very stupid but
> other than playing around with the png height and width commands which don't seem to help I have no idea of what to look for.
>
> Any suggestions or cures would be appreciated.
>
> Thanks
> #===============================================================#
>
> mydata  <- data.frame(kel = c(13,253,263,273,283,292,303,313,323,333,573,853),
>              cent=  c( -280, -40, -30, -20, -10, 1, 10, 20, 30, 40, 280, 560))
> (intervals <- diff(mydata[,1]))
>
> opar <- par(mar= (c(5, 4, 6, 2)))
>
> # png("C:/Rjunk/brendengraph.png", width=600, height=500)
>
> plot(1:12,mydata$kel, main=" ", xlab=" ",
>       ylab=" ",type="l", col="red", xaxt="n", yaxt="n",cex=.75)
>
> axis(1, at=1:12,labels=as.character(mydata$kel), cex.axis=.75)
>
> axis(3, at=1:12, labels=as.character(mydata$cent), cex.axis=.75)
>
> mtext(side = 1, line=2, text="Degrees Kelvin",cex=.75 )
> mtext(side = 3, line=2, text="Degrees Centegrade",cex=.75 )
> mtext(side=3, line=4, text="Room Temperature", font=2, cex=.85)
> # dev.off()
> par(opar)
> #=================================================================
>
> ______________________________________________
> 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.
>



-- 
Joshua Wiley
Senior in Psychology
University of California, Riverside
http://www.joshuawiley.com/



More information about the R-help mailing list