让我们从数据集开始,使其可重现:
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"))
由于我想在雷达图中特定分布牙齿,我创建了此向量,从UP4
开始,以UP3
结尾:
order_teeth <- c("UP4", "UM1", "UM2", "UM3", "LM3", "LM2", "LM1", "LP4", "LP3", "LC", "LI2", "LI1", "UI1", "UI2", "UC", "UP3")
然后,我运行以下ggplot
代码:
ggplot(data=dataset, aes(x=Tooth, y=Comparison, group=group)) +
geom_point(fill = "#F8766D", size=2.5, shape= 21, color = "black") +
scale_x_discrete(limits=c(order_teeth)) +
geom_area(alpha=0.2, position = position_identity(), color = "#F8766D", fill = "#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"))
如您所见,UP3
和UP4
之间有一个间隙,分别对应于起点和终点。 如何连接这些起点和终点?
我已经在这个论坛上阅读了有关此问题的一些问题(1,2)。但是,它们中的大多数都依赖于旋转标签。就我而言,我希望牙齿标签保留在其位置,但要缩小上间隙。
这是将ylim(25, -40)
添加到代码中的另一个版本。这样,顶部的差距更加明显。