Hello,
I am creating plots of hourly precipitation and accumulated
precipitation (on different axis, see attached image). I was wondering
how can I have the plot frame (black border) start at zero, it looks
like it is plotted less than zero?
The code I use to create the png files is below:
CairoPNG(PNG_file,width=1000, height=600, pointsize=14, bg="white")
opar <- par(mai = c(.8, .8, 1, .8)) # Set margins
plot(ppt,type="h",col="dark
grey",ylim=c(0,max_ppt+1), lwd=6,
xlab='', ylab='', main=title, frame.plot=T, axes=F)
axis(2, col="black", las=2)
par(new=T) # R to overwrite the first plot
plot(accum, type="l", col="blue", axes=F,
ylab='', xlab='', lwd=2)
axis(1, col="black", las=1)
axis(4, pretty(c(0, max_accum) ), col="black", las=2)
legend("topleft", legend=c('Incremental',
'Accumulated'),
col=c("dark grey", "blue"), lwd=c(6, 2.0))
legend((length(n)-4),max_accum,
legend=paste(round(max_accum,2)), bty="n", cex=.90) ### max accum
location
mtext(paste("Lat:", .lat, "Lon:", .lon), cex=0.95)
mtext("Index Hour", side=1, line=2)
mtext("Incremental Precipitation (in)", side=2, line=2.5)
mtext("Accumulated Precipitation (in)", side=4, line=2)
dev.off()
Thanks for all your help,
Doug
---------------------------------
Douglas M. Hultstrand, MS
Senior Hydrometeorologist
Metstat, Inc. Windsor, Colorado
voice: 970.686.1253
email: dmhultst at metstat.com
web: http://www.metstat.com
---------------------------------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mass_curve_33.355-111.325_1147_Zone1.png
Type: image/png
Size: 36251 bytes
Desc: not available
URL:
<https://stat.ethz.ch/pipermail/r-help/attachments/20100119/83b82452/attachment.png>
> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of Douglas M. Hultstrand > Sent: Tuesday, January 19, 2010 4:42 PM > To: R mailing list > Subject: [R] Plot frame border to start at zero? > > Hello, > > I am creating plots of hourly precipitation and accumulated > precipitation (on different axis, see attached image). I was wondering > how can I have the plot frame (black border) start at zero, it looks > like it is plotted less than zero?It doesn't appear to be plotted starting at less than zero. S language plots were designed from the beginning to have a little extra space around the data points so none of your data points get lost or obscured because they overstrike the borders. Thus the surrounding box is drawn about 5% outside of the data range in the X and Y axis directions, to avoid any data point overstrike. You can specify the x and y axis data ranges with the xlim and ylim arguments if you want complete control of the data range. It can be done, but you will have to work hard to get the graph to do bad things like print over your data! (See the various plot control arguments in e.g. help("par") ).> > The code I use to create the png files is below: > > CairoPNG(PNG_file,width=1000, height=600, pointsize=14, bg="white") > opar <- par(mai = c(.8, .8, 1, .8)) # Set margins > plot(ppt,type="h",col="dark grey",ylim=c(0,max_ppt+1), lwd=6, > xlab='', ylab='', main=title, frame.plot=T, axes=F) > axis(2, col="black", las=2) > par(new=T) # R to overwrite the first plot > plot(accum, type="l", col="blue", axes=F, ylab='', xlab='', > lwd=2) > axis(1, col="black", las=1) > axis(4, pretty(c(0, max_accum) ), col="black", las=2) > legend("topleft", legend=c('Incremental', 'Accumulated'), > col=c("dark grey", "blue"), lwd=c(6, 2.0)) > legend((length(n)-4),max_accum, > legend=paste(round(max_accum,2)), bty="n", cex=.90) ### max accum > location > mtext(paste("Lat:", .lat, "Lon:", .lon), cex=0.95) > mtext("Index Hour", side=1, line=2) > mtext("Incremental Precipitation (in)", side=2, line=2.5) > mtext("Accumulated Precipitation (in)", side=4, line=2) > dev.off() > > > Thanks for all your help, > Doug > > --------------------------------- > Douglas M. Hultstrand, MS > Senior Hydrometeorologist > Metstat, Inc. Windsor, Colorado > voice: 970.686.1253 > email: dmhultst at metstat.com > web: http://www.metstat.com > ---------------------------------Steven McKinney, Ph.D. Statistician Molecular Oncology and Breast Cancer Program British Columbia Cancer Research Centre email: smckinney -at- bccrc +dot+ ca tel: 604-675-8000 x7561 BCCRC Molecular Oncology 675 West 10th Ave, Floor 4 Vancouver B.C. V5Z 1L3 Canada
plot(..., xaxs='i', yaxs='i') On Tue, Jan 19, 2010 at 7:42 PM, Douglas M. Hultstrand <dmhultst at metstat.com> wrote:> Hello, > > I am creating plots of hourly precipitation and accumulated precipitation > (on different axis, see attached image). I was wondering how can I have the > plot frame (black border) start at zero, it looks like it is plotted less > than zero? > The code I use to create the png files is below: > > CairoPNG(PNG_file,width=1000, height=600, pointsize=14, bg="white") > ? ? ? opar <- par(mai = c(.8, .8, 1, .8)) ? ?# Set margins > ? ? ? plot(ppt,type="h",col="dark grey",ylim=c(0,max_ppt+1), lwd=6, xlab='', > ylab='', main=title, frame.plot=T, axes=F) > ? ? ? axis(2, col="black", las=2) > ? ? ? par(new=T) # R to overwrite the first plot > ? ? ? plot(accum, type="l", col="blue", axes=F, ylab='', xlab='', lwd=2) > ? ? ? axis(1, col="black", las=1) > ? ? ? axis(4, pretty(c(0, max_accum) ), col="black", las=2) > ? ? ? legend("topleft", legend=c('Incremental', 'Accumulated'), ?col=c("dark > grey", "blue"), lwd=c(6, 2.0)) > ? ? ? legend((length(n)-4),max_accum, legend=paste(round(max_accum,2)), > bty="n", cex=.90) ? ? ### max accum location > ? ? ? mtext(paste("Lat:", .lat, "Lon:", .lon), cex=0.95) > ? ? ? mtext("Index Hour", side=1, line=2) > ? ? ? mtext("Incremental Precipitation (in)", side=2, line=2.5) > ? ? ? mtext("Accumulated Precipitation (in)", side=4, line=2) > dev.off() > > > Thanks for all your help, > Doug > > --------------------------------- > Douglas M. Hultstrand, MS > Senior Hydrometeorologist > Metstat, Inc. Windsor, Colorado > voice: 970.686.1253 > email: dmhultst at metstat.com > web: http://www.metstat.com > --------------------------------- > > > ______________________________________________ > 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. > >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?