Very much a rookie at R, and have only recently started using it again so
pardon the simple question. I am trying to produce a box plot from one data
set and then overlay a line plot from another data set. The box plot data
set is made up of 20 sets of 30 data points, or 600 total data points. The
line has only 30 total data points. The box plot is plotting fine, but for
some reason, the line plot is starting at the 6th data position and running
off the screen. I tried modifying the text file so that the data repeated it
self 30 times to make the total number of lines in the file identical, but
that did not help! Here are my two datasets.....
temp.final.text
<http://r.789695.n4.nabble.com/file/n4643736/temp.final.text>
tmax.final.text
<http://r.789695.n4.nabble.com/file/n4643736/tmax.final.text>
And here is my script....
R --save --no-save --vanilla << EOF
pdf(file="boxplot_tmax_$YYYY$MM$DD${HH}.pdf", height=10, width=12)
soton.df = read.table ("tmax.final.text", header=TRUE)
gfs.df = read.table ("greg.txt", header=TRUE)
boxplot (TMAX ~ HOUR, data=soton.df, xlab="Forecast Hour",
ylab="MAX TEMP",
main="GEFS $YYYY$MM$DD ${HH}Z FORECAST MAX TEMPS",
whiskcol="red",
col="red", outline=TRUE,
ylim=c(0,100),xlim=c(1,30),xaxs="i",yaxs="i")
lines (data=gfs.df, type="o", col="green")
par(new=TRUE)
abline(h=seq(0,100,by=5),lty=2)
abline(v=seq(1,30,by=1),lty=2)
EOF
Thanks for helping me out!
--
View this message in context:
http://r.789695.n4.nabble.com/Line-over-Boxplot-tp4643736.html
Sent from the R help mailing list archive at Nabble.com.
Hello,
Works with me after correcting your lines() instruction. Your code
doesn't say what columns to use as coordinates, just where to look for them.
Also, (1) allways explicitly close the device using dev.off(). (2) The
grid lines were over the boxes. A way to avoid this is to plot the
boxes, then the grid, then replot the boxes with the parameter add =
TRUE (There's a function ?grid). And (3) you don't need the call to
par(new=TRUE), abline() doesn't restart the graphics device.
The full code follows.
url1 <-
"http://r.789695.n4.nabble.com/file/n4643736/tmax.final.text"
url2 <-
"http://r.789695.n4.nabble.com/file/n4643736/temp.final.text"
pdf(file="boxplot_tmax_$YYYY$MM$DD${HH}.pdf", height=10, width=12)
soton.df = read.table(url1, header=TRUE)
gfs.df = read.table(url2, header=TRUE)
boxplot (TMAX ~ HOUR, data=soton.df,
xlab="Forecast Hour", ylab="MAX TEMP",
main="GEFS $YYYY$MM$DD ${HH}Z FORECAST MAX TEMPS",
whiskcol="red", col="red", outline=TRUE,
ylim=c(0, 100), xlim=c(1, 30),
xaxs="i", yaxs="i")
abline(h=seq(0, 100,by=5), lty=2)
abline(v=seq(1, 30, by=1), lty=2)
boxplot (TMAX ~ HOUR, data=soton.df,
xlab="Forecast Hour", ylab="MAX TEMP",
main="GEFS $YYYY$MM$DD ${HH}Z FORECAST MAX TEMPS",
whiskcol="red", col="red", outline=TRUE,
ylim=c(0, 100),xlim=c(1, 30),
xaxs="i", yaxs="i",
add = TRUE)
lines(TMAX ~ HOUR, data=gfs.df, type="o", col="green")
dev.off()
Hope this helps,
Rui Barradas
Em 20-09-2012 14:41, gfishel escreveu:> Very much a rookie at R, and have only recently started using it again so
> pardon the simple question. I am trying to produce a box plot from one data
> set and then overlay a line plot from another data set. The box plot data
> set is made up of 20 sets of 30 data points, or 600 total data points. The
> line has only 30 total data points. The box plot is plotting fine, but for
> some reason, the line plot is starting at the 6th data position and running
> off the screen. I tried modifying the text file so that the data repeated
it
> self 30 times to make the total number of lines in the file identical, but
> that did not help! Here are my two datasets.....
>
> temp.final.text
> <http://r.789695.n4.nabble.com/file/n4643736/temp.final.text>
> tmax.final.text
> <http://r.789695.n4.nabble.com/file/n4643736/tmax.final.text>
>
> And here is my script....
>
> R --save --no-save --vanilla << EOF
>
> pdf(file="boxplot_tmax_$YYYY$MM$DD${HH}.pdf", height=10,
width=12)
>
> soton.df = read.table ("tmax.final.text", header=TRUE)
> gfs.df = read.table ("greg.txt", header=TRUE)
> boxplot (TMAX ~ HOUR, data=soton.df, xlab="Forecast Hour",
ylab="MAX TEMP",
> main="GEFS $YYYY$MM$DD ${HH}Z FORECAST MAX TEMPS",
whiskcol="red",
> col="red", outline=TRUE,
ylim=c(0,100),xlim=c(1,30),xaxs="i",yaxs="i")
> lines (data=gfs.df, type="o", col="green")
> par(new=TRUE)
> abline(h=seq(0,100,by=5),lty=2)
> abline(v=seq(1,30,by=1),lty=2)
>
>
>
> EOF
>
> Thanks for helping me out!
>
>
>
>
> --
> View this message in context:
http://r.789695.n4.nabble.com/Line-over-Boxplot-tp4643736.html
> Sent from the R help mailing list archive at Nabble.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.
I expect that the coordinate system being set up and used by boxplot is different from what you are expecting. See the ?boxplot and ?bxp help pages for details. You may be able to have the boxplots drawn where you expect by using the "at" argument (you may want to specify "xlim" as well). On Thu, Sep 20, 2012 at 7:41 AM, gfishel <gfishel at wral.com> wrote:> Very much a rookie at R, and have only recently started using it again so > pardon the simple question. I am trying to produce a box plot from one data > set and then overlay a line plot from another data set. The box plot data > set is made up of 20 sets of 30 data points, or 600 total data points. The > line has only 30 total data points. The box plot is plotting fine, but for > some reason, the line plot is starting at the 6th data position and running > off the screen. I tried modifying the text file so that the data repeated it > self 30 times to make the total number of lines in the file identical, but > that did not help! Here are my two datasets..... > > temp.final.text > <http://r.789695.n4.nabble.com/file/n4643736/temp.final.text> > tmax.final.text > <http://r.789695.n4.nabble.com/file/n4643736/tmax.final.text> > > And here is my script.... > > R --save --no-save --vanilla << EOF > > pdf(file="boxplot_tmax_$YYYY$MM$DD${HH}.pdf", height=10, width=12) > > soton.df = read.table ("tmax.final.text", header=TRUE) > gfs.df = read.table ("greg.txt", header=TRUE) > boxplot (TMAX ~ HOUR, data=soton.df, xlab="Forecast Hour", ylab="MAX TEMP", > main="GEFS $YYYY$MM$DD ${HH}Z FORECAST MAX TEMPS", whiskcol="red", > col="red", outline=TRUE, ylim=c(0,100),xlim=c(1,30),xaxs="i",yaxs="i") > lines (data=gfs.df, type="o", col="green") > par(new=TRUE) > abline(h=seq(0,100,by=5),lty=2) > abline(v=seq(1,30,by=1),lty=2) > > > > EOF > > Thanks for helping me out! > > > > > -- > View this message in context: http://r.789695.n4.nabble.com/Line-over-Boxplot-tp4643736.html > Sent from the R help mailing list archive at Nabble.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.-- Gregory (Greg) L. Snow Ph.D. 538280 at gmail.com
Thanks for your help! Unfortunately, I am now getting this:> pdf(file="boxplot_tmax_2012091912.pdf", height=10, width=12) > > soton.df = read.table ( tmax.final.text, header=TRUE )Error in read.table(tmax.final.text, header = TRUE) : object 'tmax.final.text' not found Execution halted The file is there, has headers, and is located in the directory I am running R in! Now I am really stumped! Greg -- View this message in context: http://r.789695.n4.nabble.com/Line-over-Boxplot-tp4643736p4643791.html Sent from the R help mailing list archive at Nabble.com.