如何在windrose图中添加图例并结合圆形函数?

时间:2018-02-19 08:34:31

标签: r simulation

感谢您的帮助。

我正在使用windRose包的函数openair来绘制当前的速度和方向。由于我在windrose功能中使用循环功能,因此它不会显示风速的色标。它确实显示了一个不使用循环函数。

我的数据排列在2列中,第1列是速度,第2列是方向(0-360)。这是我的代码:

windrose(x=circular(data$Direction,template='geographics',units = "degrees"), y=data$Speed, increment = 25,fill.col=rainbow(12),label.freq=T,xlim=c(-2.1, 2.1), ylim=c(-2.1, 2.1))

谁能解释如何获得颜色传奇? 谢谢你的帮助

1 个答案:

答案 0 :(得分:0)

首先,让我们为所有人使用一些可用的数据来重现代码。在这种情况下,它们是来自openair包的风速和方向,非常类似于您使用的流体速度和方向

library(openair)
library(circular)

# Using "mydata" dataset from openair package as an example
data <- data.frame("Speed" = mydata$ws, "Direction"=mydata$wd)

windrose(x = circular(data$Direction, template = 'geographics', units = "degrees"), 
         y = data$Speed, 
         increment = 25,
         fill.col = rainbow(12),
         label.freq = T, 
         xlim = c(-2.1, 2.1), 
         ylim = c(-2.1, 2.1))

不确定您使用的是哪个openair软件包版本(我的是2.1.5),但您的函数调用与帮助中的签名不匹配(参数名称不同)。您可以使用以下方法在帮助中查看它们:

help(windRose) 

话虽如此,我还建议您分两步拆分代码:

1)创建数据集。 windRose函数查找变量名ws(风速[m / s])和wd(风向[度为北]),您可以使用它们。确保数据框包含正确的值和单位。使用head(data2)str(data2)进行可视化。请注意,此处data是您自己的数据集。

data2 <- data.frame("ws" = as.numeric(circular(data$Direction, template = 'geographics', units = "degrees")), 
                    "wd" = data$Direction)

2)用wswd变量名称绘制数据框。

data <- data.frame("Speed" = mydata$ws, "Direction"=mydata$wd)
data2 <- data.frame("ws"=data$Speed, "wd"=data$Direction)
head(data2)
    ws  wd
1 0.60 280
2 2.16 230
3 2.76 190
4 2.16 170
5 2.40 180
6 3.00 190
windRose(data2)

enter image description here