Lets start with the dataset, to make it reproducible:
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"))
As I want a specific distribution of the teeth in the radar chart, I created this vector, starting with UP4
and ending with UP3
:
order_teeth <- c("UP4", "UM1", "UM2", "UM3", "LM3", "LM2", "LM1", "LP4", "LP3", "LC", "LI2", "LI1", "UI1", "UI2", "UC", "UP3")
Then, I run this ggplot
code:
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"))
As you can see, there is a gap between UP3
and UP4
, which correspond to the starting and ending points. How can I connect these starting and ending points?
I've been reading in this forum some questions about this issue (1, 2). However, most of them relied on rotating the labels. In my case, I want the tooth labels to remain in its place, but closing the upper gap.
This is another version adding ylim(25, -40)
to the code. In this way, the gap is more evident at the top.