I have a plot with points on a polar coordinate system. Each point has an associated label, which should be shown around the plot at the given angle. This can be achieved either using axis.text or geom_text; I have used geom_text here. Unfortunately, the text labels overlap. Using position = position_jitter() apparently only allows jittering by height, but not by width (i.e., does not solve the issue). MWE:
df <- data.frame("angle" = runif(50, 0, 359),
"projection" = runif(50, 0, 1),
"labels" = paste0("label_", 1:50))
ggplot(data = df, aes(x = angle, y = projection, label = labels)) +
geom_point() +
coord_polar() +
theme_minimal() +
geom_text(aes(x=angle, y=1.1,
label=labels),
size = 3)
I would like to jitter the labels such that they do not overlap, but stay outside the plotting area. I have also tried to use the angle argument to conditionally angle the labels to make more space, but couldn't figure out the right formula to make the angles work.
Edit: Here is another way to create the plot, using scale_x_continuous to create the labels as axis.text.x. This does, however, again lead to overlapping labels.
ggplot(data = df, aes(x = angle, y = projection, label = labels)) +
geom_point() +
coord_polar() +
scale_x_continuous(limits = c(0, 360), expand = c(0, 0), breaks = df$angle, labels=df$labels) +
theme_minimal() +
theme(panel.grid = element_blank())