R plot dynamic wind direction as arrow over time
Asked Answered
S

1

1

I want to plot the wind over a very long time,thus a dynamic plot is a nice choice for others to choose the time range. And I want to display the wind direction as arrows; wind speed could be line.

But it will be messy if I add arrows to every line above, and it seems hard to add more date to x axis. What the final result I want to get is like this:

enter image description here

Is it possible to plot the wind-arrow plot in R?

Plus: here is the demo data for plot

structure(list(date = c("2016-04-01", "2016-04-01", "2016-04-01", 
"2016-04-01", "2016-04-01", "2016-04-01", "2016-04-01", "2016-04-01", 
"2016-04-01", "2016-04-01", "2016-04-01", "2016-04-01", "2016-04-01", 
"2016-04-01", "2016-04-01", "2016-04-01", "2016-04-01", "2016-04-01", 
"2016-04-01", "2016-04-01", "2016-04-01", "2016-04-01", "2016-04-01", 
"2016-04-01", "2016-04-02", "2016-04-02", "2016-04-02", "2016-04-02", 
"2016-04-02", "2016-04-02", "2016-04-02", "2016-04-02", "2016-04-02", 
"2016-04-02", "2016-04-02", "2016-04-02", "2016-04-02", "2016-04-02", 
"2016-04-02", "2016-04-02", "2016-04-02", "2016-04-02", "2016-04-02", 
"2016-04-02", "2016-04-02", "2016-04-02", "2016-04-02", "2016-04-02"
), time = c("0:00:00", "1:00:00", "2:00:00", "3:00:00", "4:00:00", 
"5:00:00", "6:00:00", "7:00:00", "8:00:00", "9:00:00", "10:00:00", 
"11:00:00", "12:00:00", "13:00:00", "14:00:00", "15:00:00", "16:00:00", 
"17:00:00", "18:00:00", "19:00:00", "20:00:00", "21:00:00", "22:00:00", 
"23:00:00", "0:00:00", "1:00:00", "2:00:00", "3:00:00", "4:00:00", 
"5:00:00", "6:00:00", "7:00:00", "8:00:00", "9:00:00", "10:00:00", 
"11:00:00", "12:00:00", "13:00:00", "14:00:00", "15:00:00", "16:00:00", 
"17:00:00", "18:00:00", "19:00:00", "20:00:00", "21:00:00", "22:00:00", 
"23:00:00"), ws = c(0.6, 0.6, 0.3, 0.3, 0.5, 0.5, 0.4, 0.4, 0.4, 
0.6, 0.9, 0.4, 0.9, 2.3, 2, 2.5, 2.6, 2.4, 2, 2.2, 1.7, 1.2, 
1, 1, 1.4, 1.1, 1.4, 0.8, 1, 1.5, 1.2, 1.3, 1.4, 1.3, 2, 2.1, 
2.7, 2.2, 2.1, 2.5, 1.9, 2, 1.7, 1.9, 1.2, 0.4, 0.5, 0.4), wd = c(179, 
151.5, 200, 178.7, 205.5, 115.1, 110.9, 175.7, 192.9, 121, 117.5, 
171.7, 204.8, 160.7, 169.3, 171, 169.4, 172.8, 154.5, 170.6, 
151, 131.1, 105.3, 109.5, 141.9, 137.1, 113.7, 116.6, 88.7, 110.1, 
99.9, 105.5, 98.4, 101.3, 128.6, 146.9, 148.1, 148.4, 152.5, 
144.1, 145, 160, 179.2, 147.3, 156.6, 147.1, 158, 157.9)), .Names = c("date", 
"time", "ws", "wd"), class = "data.frame", row.names = c(NA, 
-48L))

________________________________update________________________________________

Sorry for not emphasising my problem.

Thanks @koekenbakker ,the function doing well in plotting the wind direction and the speed in one plot.Otherwise,my problem may focus more on how to convert the wind plot to a dynamic plot.(dynamic in date selection is enough)

Simulator answered 11/7, 2016 at 4:2 Comment(4)
You should be able to do this with geom_line and geom_spoke with arrow = arrow() (you'll need to convert wd to radians), but for the life of me I can't get the arrows to point in the right directions.Spada
Having the date & time as in a datetime (eg POSIXct) class would make plotting the x-axis much easierDorindadorine
@Spada well I have try to do this use geom_line and geom_segmentwitharrow=arrow() using the sin() and cos() .But it still be hard to dynamic display the result.Simulator
@Richard Telford Sorry for that demo data,I have handle the two columns using paste() and strptime()Simulator
M
0

Try the Arrowhead function in the shape package with the angle argument:

angle of arrowhead (anti-clockwise, relative to x-axis), in degrees [0,360]; either one value or a vector

I'm not sure this matches with your description of wind direction, perhaps you need to subtract your wind directions from 360 degrees or something similar.

library(shape)
plot(1:nrow(a), rep(1,nrow(a)), pch=NA, ylim=c(0,5))
Arrowhead(x0 = 1:nrow(a), y0 = a$ws, angle=a$wd)
Marinemarinelli answered 11/7, 2016 at 7:30 Comment(2)
Yeah,this answer satisfy one part of my problem,about the direction of the wind,and the speed of wind is also display very well.But there is another problem I want solve is how to dynamic select the date range. In ggplot2,I can creat simlar plot like the Arrowhead do.For a ggplot object ,I could do the dynamic use the ggplotlyfunction,but it seems less stable,I have look for the package dygraph,but in its example demo ,I find it do well in line chart,maybe not an arrow or a segment chart?Simulator
I'm afraid I can't help you with that part of the question.Marinemarinelli

© 2022 - 2024 — McMap. All rights reserved.