You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

openair windRose:移除标题统计信息、保留方向并增大图例尺寸的方法

解决openair windRose两个问题的方案

1. 只移除标题和统计信息,保留方位标识

不要设置annotate = FALSE(会丢失方位),而是保持annotate = TRUE,再通过修改生成的ggplot对象移除主标题和统计文本:

library(openair)

# 绘制风玫瑰图,先保留方位标识,同时清空主标题
p <- windRose(wind_rose_feb_apr_2008_2022, ws = "Speed", wd = "Direction",
              breaks = c(0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55),
              auto.text = TRUE, paddle = FALSE,
              max.freq = 25, angle = 22.5, annotate = TRUE, cols = "jet", 
              key.position = "bottom", key.header = "Wind Speed (knots)", 
              key.footer = " ", offset=5, main = "")

# 移除统计信息文本图层(如观测数、平均风速等内容)
p$layers <- p$layers[-which(sapply(p$layers, function(x) inherits(x, "GeomText")))]

# 确保主标题完全隐藏
p <- p + theme(plot.title = element_blank())

2. 增大图例尺寸,避免文字拥挤

有两种方式可以调整:

方式一:调用windRose时直接缩放图例

在函数参数中添加key.args = list(cex = 1.2)(cex值大于1即可放大,可根据需求调整):

p <- windRose(wind_rose_feb_apr_2008_2022, ws = "Speed", wd = "Direction",
              breaks = c(0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55),
              auto.text = TRUE, paddle = FALSE,
              max.freq = 25, angle = 22.5, annotate = TRUE, cols = "jet", 
              key.position = "bottom", key.header = "Wind Speed (knots)", 
              key.footer = " ", offset=5, main = "",
              key.args = list(cex = 1.2))  # 整体放大图例比例

方式二:精细调整图例元素

如果需要单独控制符号大小、文字大小,用ggplot的theme函数设置:

p <- p + theme(
  legend.key.size = unit(12, "mm"),  # 增大图例色块/符号尺寸
  legend.text = element_text(size = 10),  # 调整图例文字大小
  legend.title = element_text(size = 12)  # 调整图例标题大小
)

完整代码示例

合并所有调整步骤:

library(openair)

# 绘制并调整风玫瑰图
p <- windRose(wind_rose_feb_apr_2008_2022, ws = "Speed", wd = "Direction",
              breaks = c(0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55),
              auto.text = TRUE, paddle = FALSE,
              max.freq = 25, angle = 22.5, annotate = TRUE, cols = "jet", 
              key.position = "bottom", key.header = "Wind Speed (knots)", 
              key.footer = " ", offset=5, main = "",
              key.args = list(cex = 1.2))

# 移除统计信息和主标题
p$layers <- p$layers[-which(sapply(p$layers, function(x) inherits(x, "GeomText")))]
p <- p + theme(plot.title = element_blank())

# 显示图形
print(p)

内容的提问来源于stack exchange,提问作者gillisr

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 19:23:08