I'd like to plot a stick plot for wind speed/ direction data similar to this:
I've found a good plot in the excelent oce package, but I'd like to make this same kind of plot using ggplot (or plotley).
WindSpeed<-c(1,2,3,5,7,2,3,4,5,6,7,8)
WindDir<-c(180,90,320,200,350,10,270,50,9,100,110,129)
TimeStamp<-c("2018-01-02 01:00","2018-01-02 02:00","2018-01-02 03:00","2018-01-02 04:00","2018-01-02 05:00","2018-01-02 06:00","2018-01-02 07:00","2018-01-02 08:00","2018-01-02 09:00","2018-01-02 10:00","2018-01-02 11:00","2018-01-02 12:00")
DF<-data.frame(TimeStamp,WindSpeed, WindDir)
The above Wind direction data is in compass direction units (the compass direction the wind is blowing from), so I'd like the 180 data to point straight up, and the 270 data point to point straight to the right (AKA coming from the west and blowing East).
segments
and some trig functions would work well enough. (You'll also needas.POSIXct
to convert your timestamp, though you'll need to add:00
to each.) - r2evans:00
- hrbrmstrgeom_segment(aes(x = hour, y = 0, xend = TimeStamp + lubridate::dhours(WindSpeed * 1 * -cos(WindDir / 360 * 2 * pi)), yend = WindSpeed * 1 * -sin(WindDir / 360 * 2 * pi)))
in combination withcoord_fixed(ratio = 60 * 60)
. - Jon Spring":00"
- r2evans