[R] Need help plotting

Jim Lemon drj|m|emon @end|ng |rom gm@||@com
Tue Sep 20 09:37:50 CEST 2022


Hi David,
I'm back home again. Try this:

b<-read.table(text=
"Dtime DNO2 DVOC     Dpm10    Dpm2.5 Dpm1 Mtime MNO2 MVOC    Mpm10 Mpm2.5 Mpm1
 18:00   28  164  81.34773 24.695435   14 18:00   19  151 3.000000      2    1
 18:01   27  163  74.44034 23.751198   14 18:01   20  148 3.000000      2    1
 18:02   30  160  72.21975 22.463129   13 18:02   19  150 3.000000      2    1",
 header=TRUE,stringsAsFactors=FALSE)
b$POSIXtime<-strptime(paste("2022-09-20",b$Dtime),"%Y-%m-%d %H:%M")
png("DFPNO2.png")
plot(b$POSIXtime,b$DNO2,type="b",main="NO2 readings (2022-09-20)",
 xlab="Date/time",ylab="NO2",ylim=range(c(b$DNO2,b$MNO2)),
 pch=19,col="red")
 points(b$POSIXtime,b$MNO2,type="b",pch=19,col="blue")
 legend("center",legend=c("DNO2","MNO2"),pch=19,col=c("red","blue"))
dev.off()

If you have more than one day, it will show up on the x axis. You can
also format the tick labels if you want the full dates for only one
day.

Jim

PS thanks Avi

On Tue, Sep 20, 2022 at 4:49 PM Parkhurst, David <parkhurs using indiana.edu> wrote:
>
> Thank you.
>
> DFP (iPad)
>
> > On Sep 19, 2022, at 8:15 AM, Ebert,Timothy Aaron <tebert using ufl.edu> wrote:
> >
> > My version of this email has a bunch of ? that I do not know how to interpret. Emails to this group need to be in plain text. HTML content is deleted or converted and impossible or at least difficult to interpret.
> >
> > Do not share confidential data. Please change some numbers or variable names and share that.
> > If this helps:
> > 1) Make sure your time variable is a datetime object.
> > 2) At least in ggplot it should now behave as expected.
> > ggplot(df, aes(y=NO2, x=datetime)) + geom_point()
> >
> > That will be a start as a scatterplot, but the graph can be customized or changed if scatterplot was not desired.
> >
> > Tim
> >
> > -----Original Message-----
> > From: R-help <r-help-bounces using r-project.org> On Behalf Of Parkhurst, David
> > Sent: Sunday, September 18, 2022 4:27 PM
> > To: r-help using r-project.org
> > Subject: [R] Need help plotting
> >
> > [External Email]
> >
> > I�ve been retired since �06 and have forgotten most of R.  Now I have a use for it, with some data from Bloomington�s Environmental Commission.
> >
> > I have a dataframe (obtained from read.csv) that contains numerous columns, including time (in Excel�s 18:00 format), and DNO2, and MNO2 from two air quality instruments.
> >
> > I�d like a plot of both the NO2 measurements against time.  I be happy to use either ordinary R plots or ggplot2 ones, if that would be a better way.  I�d much appreciate help.
> >
> >        [[alternative HTML version deleted]]
> >
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: DFPNO2.png
Type: image/png
Size: 16491 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20220920/a2fded16/attachment.png>


More information about the R-help mailing list