R将动态风向绘制为箭头随时间变化

R将动态风向绘制为箭头随时间变化

本文介绍了R将动态风向绘制为箭头随时间变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想绘制很长一段时间的,因此动态图表是其他人选择时间范围的不错选择.我想将风向显示为箭头;风速可能是线.

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.

但是,如果我在上面的每一行中添加箭头,将会很混乱,并且似乎很难在x轴上添加更多日期.我想要得到的最终结果是这样的:

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:

是否可以在R中绘制风向图?

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.

感谢@koekenbakker,该功能在绘制风向和风速的一个图中效果很好.否则,我的问题可能更多地集中在如何将风向转换为动态上.(动态选择日期就足够了

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)

推荐答案

尝试使用angle参数在shape包中使用Arrowhead函数:

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

我不确定这与您对风向的描述是否匹配,也许您需要从360度或类似的角度减去风向.

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)

这篇关于R将动态风向绘制为箭头随时间变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 09:28