这是我使用ggplot2
获取雷达图的代码:
ggplot(data=dataset, aes(x=Tooth, y=Comparison, group=group)) +
geom_point(color = "#F8766D", size=1.5) +
geom_line(lty = 2) +
geom_area(alpha=0.2, position = position_identity(), color = "#F8766D") +
geom_hline(aes(group=group, yintercept=0), lwd=1, lty=2, alpha=0.5) +
coord_polar() +
theme(legend.key = element_blank(), panel.background = element_blank(), panel.grid.major = element_line(colour = "gray92"))
这是结果图。
我的问题是:
如何更改现在为灰色的区域的颜色?我在color = "#F8766D"
函数中添加了geom_area()
,最终使线着色,但未着色区域。
如您所见,该区域并非完全封闭。那么,如何关闭UP3和UP4之间的区域?它们被放置在雷达的顶部。
您可能会注意到,LI1没有数据,这就是为什么该观察没有意义的原因。这导致该区域中的间隙。如何将点从LI2连接到UI1,以避免丢失数据并因此关闭区域?
这是使用dput()
获得的数据集:
structure(list(dataset = c(-23.8789646372585, NaN, -10.8009305417082,
-11.8411770633881, -19.000246852629, -14.364572544966, -21.8175372410621,
-25.4455825234135, -16.3659714913407, -24.2952691912406, -0.794961013892774,
9.27790872080566, -20.9411764705882, -20.3132576468705, -25.1353910061732,
-17.0200414318061), Tooth = c("UI1", "LI1", "UI2", "LI2", "UC",
"LC", "UP3", "LP3", "UP4", "LP4", "UM1", "LM1", "UM2", "LM2",
"UM3", "LM3"), group = c("a", "a", "a", "a", "a", "a", "a", "a",
"a", "a", "a", "a", "a", "a", "a", "a")), .Names = c("Comparison",
"Tooth", "group"), class = "data.frame", row.names = c("UI1",
"LI1", "UI2", "LI2", "UC", "LC", "UP3", "LP3", "UP4", "LP4",
"UM1", "LM1", "UM2", "LM2", "UM3", "LM3"))