我正在尝试使用
ggplot2
在 R 中绘制一个简单的极坐标图,但我正在与奇怪的行为作斗争!
这是我的数据集:
wake_loss_per_sector
sector wake_loss angle
1 1 16.48843 30
2 2 17.59385 60
3 3 19.19244 90
4 4 27.17434 120
5 5 26.13185 150
6 6 10.95055 180
7 7 11.09595 210
8 8 14.24783 240
9 9 15.59619 270
10 10 19.09893 300
11 11 22.63984 330
12 12 15.84240 0
这是我如何尝试绘制它的:
ggplot(wake_loss_per_sector, aes(x = angle, y = wake_loss)) +
geom_col(width = 25, fill = "skyblue", color = "black") +
coord_polar(start = 0) +
scale_x_continuous(
limits = c(0, 360),
breaks = seq(0, 330, by = 30),
minor_breaks = NULL
) +
theme_minimal()
当它运行时,它会生成警告:
Warning message:
Removed 1 rows containing missing values (`geom_col()`).
该图如下所示,缺少扇区 12(0 度):
任何建议都将受到高度赞赏!
删除
limits = c(0, 360)
:
library(ggplot2)
wake_loss_per_sector <- data.frame(
sector = 1:12,
wake_loss = c(16.48843, 17.59385, 19.19244, 27.17434, 26.13185, 10.95055,
11.09595, 14.24783, 15.59619, 19.09893, 22.63984, 15.84240),
angle = c(30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330, 0)
)
# Plot
ggplot(wake_loss_per_sector, aes(x = angle, y = wake_loss)) +
geom_col(width = 30, fill = "skyblue", color = "black") +
coord_polar(start = 0) +
scale_x_continuous(
breaks = seq(0, 330, by = 30)
) +
theme_minimal() +
labs(x = "Angle (degrees)", y = "Wake Loss", title = "Polar Plot of Wake Loss by Sector")