【发布时间】:2017-03-12 14:14:08
【问题描述】:
我正在尝试绘制膨胀方向(md$Swell.Dir 和高度(md$m),以便结果类似于下图;
这是我使用 dput 的一小部分数据;
md <- structure(list(UTC = structure(1:6, .Label = c("01-Feb-17 1200",
"01-Feb-17 1500", "01-Feb-17 1800", "01-Feb-17 2100", "02-Feb-17 0000",
"02-Feb-17 0300", "02-Feb-17 0600", "02-Feb-17 0900", "02-Feb-17 1200",
"02-Feb-17 1500", "02-Feb-17 1800", "02-Feb-17 2100", "03-Feb-17 0000",
"03-Feb-17 0300", "03-Feb-17 0600", "03-Feb-17 0900", "03-Feb-17 1200",
"03-Feb-17 1500", "03-Feb-17 1800", "03-Feb-17 2100", "04-Feb-17 0000",
"04-Feb-17 0300", "04-Feb-17 0600", "04-Feb-17 0900", "04-Feb-17 1200",
"04-Feb-17 1500", "04-Feb-17 1800", "04-Feb-17 2100", "05-Feb-17 0000",
"05-Feb-17 0300", "05-Feb-17 0600", "05-Feb-17 0900", "05-Feb-17 1200",
"05-Feb-17 1500", "05-Feb-17 1800", "05-Feb-17 2100", "06-Feb-17 0000",
"06-Feb-17 0300", "06-Feb-17 0600", "06-Feb-17 0900", "06-Feb-17 1200",
"06-Feb-17 1500", "06-Feb-17 1800", "06-Feb-17 2100", "07-Feb-17 0000",
"07-Feb-17 0300", "07-Feb-17 0600", "07-Feb-17 0900", "07-Feb-17 1200",
"07-Feb-17 1500", "07-Feb-17 1800", "07-Feb-17 2100", "08-Feb-17 0000",
"08-Feb-17 0300", "08-Feb-17 0600", "08-Feb-17 0900", "08-Feb-17 1200",
"08-Feb-17 1500", "08-Feb-17 1800", "08-Feb-17 2100", "09-Feb-17 0000"
), class = "factor"), SigWave.m = c(1.7, 1.7, 1.6, 1.6, 1.7,
1.8), WindWave.Dir = c(140L, 141L, 142L, 180L, 150L, 150L), Metres = c(1.7,
1.7, 1.6, 1.6, 1.7, 1.7), WindWave.s = c(5.8, 5.7, 5.7, 5.5,
5.4, 5.4), Swell.Dir = c(17L, 18L, 24L, 11L, 12L, 12L), m = c(0.5,
0.5, 0.5, 0.3, 0.2, 0.2), Wave1.Dir = c(137L, 137L, 137L, 137L,
141L, 143L)), .Names = c("UTC", "SigWave.m", "WindWave.Dir",
"Metres", "WindWave.s", "Swell.Dir", "m", "Wave1.Dir"), row.names = c(NA,
6L), class = "data.frame")
首先我将日期更改为正确的格式:
md$UTC <-as.POSIXct(md$UTC, format = "%d-%b-%y %H%M")
根据geom_spoke包;
“这是 geom_segment 的极坐标参数化。当您有 > 描述方向和距离的变量时,它很有用。”
由于我的膨胀方向是极化的,我相信 geom_spoke 是正确使用的 geom 函数。然而,下面的代码并没有给我想要的结果,并且辐条没有极化方向。
ggplot(data = md) + geom_spoke(mapping = aes(x = UTC, y = m, angle = Swell.Dir, radius = 0.5 ))
这是 geom_spoke 函数的输出。
我在这些链接here、here 和here 上阅读过类似的问题,但尝试建议的解决方案并没有给我想要的结果。我认为我的问题可能在于 ggplot 如何计算 geom_segment 函数的 xend yend 参数,但我找到了解决此问题的方法。
感谢您的帮助。
【问题讨论】: