【问题标题】:How to add legend to windrose plot combined with circular function?如何在结合循环函数的风玫瑰图中添加图例?
【发布时间】:2018-02-20 18:42:39
【问题描述】:

感谢您的帮助。

我正在使用 R 的 openair 包的函数 windRose 来绘制当前速度和方向。由于我在 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))

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

【问题讨论】:

标签: r simulation


【解决方案1】:

首先,让我们使用一些可用的数据来重现代码。在这种情况下,它们是来自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 (Wind Speed [m/s]) 和 wd (Wind Direction [deg from North]),您可以使用它们。确保数据框包含正确的值和单位。使用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)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-05
    相关资源
    最近更新 更多