[R] Plotting wind direction as arrows with precipitation
DJ L
rhelp10 at gmail.com
Wed Aug 26 23:05:39 CEST 2015
Hello All,
Thank you so much for replying. Sorry I have been out of contact, I was in
the field with limited internet collecting more data. I will read over the
suggestions and will provide feedback or more questions. Looks like I have
some looking up to do on the packages suggested.
Also something I should have included was a general picture idea. See
picture attached of the goal in mind. I was able to create a rose diagram
with the wind data, but that is more of a summary vs time series showing
the direction and time.
I have also separated the degrees into 8 categories, to simply things. Rose
diagram, also attached.
Thank you again and talk soon!
On Tue, Aug 11, 2015 at 12:52 PM, John Kane <jrkrideau at inbox.com> wrote:
> Thanks Bert,
> I think that arrow() would do what the OP needs. The main problem would
> be calculating the angles properly if I understand the issue. Still there
> cannot be "that" many points on a compass, can there?
>
> John Kane
> Kingston ON Canada
>
>
> > -----Original Message-----
> > From: bgunter.4567 at gmail.com
> > Sent: Tue, 11 Aug 2015 07:55:55 -0700
> > To: jrkrideau at inbox.com
> > Subject: Re: [R] Plotting wind direction as arrows with precipitation
> >
> > ... don't know if this will help, but grid graphics, which is the
> > graphics engine for both trellis and ggplot, has a basic arrow()
> > function. Trellis's provides an interface to it with the
> > panel.arrows() panel function. I suspect ggplot has something similar,
> > but as I don't use it, I don't know for sure.
> >
> > There is also an arrows() function in the basic (non-grid) graphics
> > engine, but this is probably irrelevant for your needs.
> >
> > Cheers,
> > Bert
> >
> >
> > Bert Gunter
> >
> > "Data is not information. Information is not knowledge. And knowledge
> > is certainly not wisdom."
> > -- Clifford Stoll
> >
> >
> > On Tue, Aug 11, 2015 at 7:16 AM, John Kane <jrkrideau at inbox.com> wrote:
> >> Hi,
> >> Good example and data. Thanks.
> >>
> >> Here are a couple of approaches that may help.
> >> I tend to use a lot of what I tend to think of as the ggplot family of
> >> associated so you may need to install a couple packages. I used
> >> lubridate to transform your character dates to POSIXct. Jeff N's code
> >> does exatly the same in base R. so you don't really need the lubridate
> >> package.
> >>
> >> I changed the data set name to dat1 and transformed the column names to
> >> lower case just for my convenience. Data is now in dput() form. See
> >> ?dput() for more information. It is the preferred way to share data on
> >> R-help
> >>
> >> Given what appears to be vastly different y-scales for rainfall and wind
> >> direction it struck me that it might be better to have the data in two
> >> plots so I included that option.
> >>
> >> I am not really sure how to get the arrows you want. You may be able to
> >> do it using scale_shape_manual but I am not sure if the required
> >> symbols are available.
> >>
> >> You may have to manually draw them. See
>
> http://stackoverflow.com/questions/3421331/example-needed-using-arrow-with-ggplot2
> >> for how to draw an arrow.
> >>
> >> John Kane
> >> Kingston ON Canada
> >> ##============Start code==============
> >> library(ggplot2)
> >> library(reshape2)
> >> library(lubridate)
> >> library(gridExtra)
> >>
> >> dat1 <- structure(list(deal1 = c("10/22/2012 0:00", "10/22/2012 0:15",
> >> "10/22/2012 0:30", "10/22/2012 0:45", "10/22/2012 1:00", "10/22/2012
> >> 1:15"
> >> ), rainfall_cm = c(0L, 0L, 0L, 0L, 0L, 0L), wind_direction1 = c(296L,
> >> 317L, 323L, 323L, 326L, 326L), wind_direction2 = c("W", "NW",
> >> "NW", "NW", "NW", "NW")), .Names = c("deal1", "rainfall_cm",
> >> "wind_direction1", "wind_direction2"), class = "data.frame", row.names =
> >> c(NA,
> >> -6L))
> >>
> >>
> >> dat1$deal1 <- mdy_hm(dat1$deal1) # Lazy man's equivalent of Jeff N's
> >> Sandy$Deal1 <- as.POSIXct( Sandy$Deal1, format="%m/%d/%Y %H:%M")
> >>
> >> dat2 <- melt(dat1[ , 1:3], id.var = "deal1") # use reshape to
> >> rearrange data.
> >> p <- ggplot(dat2, aes(deal1, value, colour = variable) )+ geom_point()
> >> p
> >>
> >> ## possible option
> >> g1 <- ggplot(dat1, aes(deal1, wind_direction1)) + geom_point() +
> >> theme(axis.title.x=element_blank())
> >> g2 <- ggplot(dat1, aes(deal1, rainfall_cm ) )+ geom_point()
> >>
> >> grid.arrange( g1, g2, ncol=1)
> >>
> >> ##===========end code==================
> >>
> >>
> >>> -----Original Message-----
> >>> From: rhelp10 at gmail.com
> >>> Sent: Mon, 10 Aug 2015 00:05:27 -0400
> >>> To: r-help at r-project.org
> >>> Subject: [R] Plotting wind direction as arrows with precipitation
> >>>
> >>> Hello R users!
> >>>
> >>> I am trying to create a time series in R with two variables,
> >>> precipitation
> >>> and wind direction vs Date/Time.
> >>>
> >>> I am looking for suggestions and maybe even sample code.
> >>>
> >>> My workbook is called "Sandy" and has columns with Date/Time,
> >>> Raindall_cm,
> >>> Wind Direction in both degree format (0-359) and in character form (N,
> >>> NW,
> >>> S, SW, SE, E, NE, NW).
> >>>
> >>> I have done some reading for it on stackoverflow and other sites but
> >>> not
> >>> making head way.
> >>>
> >>> I will be graphing with ggplot most likely and am a beginner in R, self
> >>> taught from books and online resources.
> >>>
> >>> This is the code I have and a small peak into the data.
> >>>
> >>> Sandy<-read.csv("Sandy.csv", header=TRUE,
> >>> sep=",",stringsAsFactors=FALSE)
> >>>> head(Sandy)
> >>> Deal1 Rainfall_cm Wind_Direction1 Wind_Direction2
> >>> 1 10/22/2012 0:00 0 296 W
> >>> 2 10/22/2012 0:15 0 317 NW
> >>> 3 10/22/2012 0:30 0 323 NW
> >>> 4 10/22/2012 0:45 0 323 NW
> >>> 5 10/22/2012 1:00 0 326 NW
> >>> 6 10/22/2012 1:15 0 326 NW
> >>>
> >>>> class(Sandy)
> >>> [1] "data.frame"
> >>>
> >>>> str(Sandy)
> >>> 'data.frame': 1832 obs. of 4 variables:
> >>> $ Deal1 : chr "10/22/2012 0:00" "10/22/2012 0:15" "10/22/2012
> >>> 0:30" "10/22/2012 0:45" ...
> >>> $ Rainfall_cm : num 0 0 0 0 0 0 0 0 0 0 ...
> >>>
> >>> $ Wind_Direction: num 296 317 323 323 326 326
> >>>
> >>> $ Wind_Direction: chr "W" "NW" "NW" "NW" ...
> >>>
> >>>> require(ggplot2)
> >>> Loading required package: ggplot2
> >>>
> >>> # this graph does the precipitation vs time graph, but not the wind
> >>>
> >>>> ggplot(Sandy, aes(x = Deal1, y = Rainfall_cm, group = 1)) +
> >>> geom_line(stat = "identity")
> >>>
> >>>
> >>> Ideally I want it to have the precipitation graph vs time, then wind vs
> >>> time on the same graph. I would like the wind direction to be arrows
> >>> pointing in the designated direction (i.e. North points north).
> >>>
> >>> Thank you!
> >>>
> >>> [[alternative HTML version deleted]]
> >>>
> >>> ______________________________________________
> >>> R-help at 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.
> >>
> >> ____________________________________________________________
> >> FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on
> >> your desktop!
> >>
> >> ______________________________________________
> >> R-help at 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.
>
> ____________________________________________________________
> FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop!
> Check it out at http://www.inbox.com/earth
>
>
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: example.png
Type: image/png
Size: 151219 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20150826/337e567c/attachment.png>
More information about the R-help
mailing list