用ggplot连接极坐标图中的起点和终点,以保持观测的位置

时间:2018-07-06 07:45:52

标签: r ggplot2

让我们从数据集开始,使其可重现:

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"))

enter image description here

如您所见,UP3UP4之间有一个间隙,分别对应于起点和终点。 如何连接这些起点和终点?

我已经在这个论坛上阅读了有关此问题的一些问题(12)。但是,它们中的大多数都依赖于旋转标签。就我而言,我希望牙齿标签保留在其位置,但要缩小上间隙。

这是将ylim(25, -40)添加到代码中的另一个版本。这样,顶部的差距更加明显。

enter image description here

0 个答案:

没有答案
相关问题