I can generate beautiful polar/radar charts with the function coord_polar()
in ggplot2
. They are a very illustrative way to summarize graphically your data. However, when tracing a line and coloring the area defined by that line, I see it is not totally closed. That is, there is a gap between the first point included in the chart and the last one. To illustrate this, let's use my dataset:
dataset <- structure(list(Comparison = c(NA, NA, 8.74089490114464, NA, -21.4860528264626,
-39.2776554202867, -17.6623719989853, -24.6866200381506, -14.7775465072786,
-7.63468366388391, -11.085710605963, 19.9485934599457, -4.60660415817366,
-19.826927971494, NA, -3.27723649247121), 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"))
I employed this ggplot
code:
order_teeth <- c("UP4", "UM1", "UM2", "UM3", "LM3", "LM2", "LM1", "LP4", "LP3", "LC", "LI2", "LI1", "UI1", "UI2", "UC", "UP3")
ggplot(data=na.omit(dataset), aes(x=Tooth, y=Comparison, group=group)) +
ylab("%diff") +
ylim(25, -40) +
xlab("GroupA vs GroupB") +
scale_x_discrete(limits=c(order_teeth)) +
geom_area(alpha=0.2, position = position_identity(), color = "#7CAE00", fill = "#7CAE00") +
geom_hline(aes(group=group, yintercept=0), lwd=1, lty=5, alpha=0.8) +
geom_hline(aes(group=group, yintercept=mean(dataset$Comparison, na.rm = TRUE)), lwd=0.75, lty=2, alpha=0.8, color="darkgreen") +
geom_point(fill = "#7CAE00", size=2.5, shape= 21, color = "black") +
coord_polar() +
theme(legend.key = element_blank(), panel.background = element_blank(), panel.grid.major = element_line(colour = "gray92"))
As you can see, I first defined the exact order I want categories (in this case teeth) to appear around the radar chart. Later, I run the ggplot
figure. I create this fantastic plot:
However, I need to solve one important thing: close the line and color the area highlighted in the red circle of the next image. And most importantly, and I am telling this because I read it elsewhere, the position of the teeth (darkred arrows) must remain unmoved.
How can I modify the code to get these issues?