[R] Plotting wind direction as arrows with precipitation

Jeff Newmiller jdnewmil at dcn.davis.CA.us
Mon Aug 10 14:01:31 CEST 2015


I don't see any conversion of your time data from character to a time type, so it is probably converting to factor within the ggplot function. Something like

Sys.setenv(TZ="Etc/GMT+5") # you need to study time types, including ?strptime

Sandy$Deal1 <- as.POSIXct( Sandy$Deal1, format="%m/%d/%Y %H:%M")

The other problem I see is that you probably need to have your data in long form to get the results you want, so you should look at the vignettes for the reshape2 or tidyr packages.
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.

On August 10, 2015 12:05:27 AM EDT, DJ L <rhelp10 at gmail.com> wrote:
>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.



More information about the R-help mailing list