Curve text around coord_polar plot

Using example and answer from this SO post:

library(ggplot2) # ggplot2_2.2.1

# data
df1 <- data.frame(a = c("sensor 1","sensor 2","sensor 3","sensor 4",
                        "sensor very very long text 5",
                        "sensor 6","sensor 7","sensor 8"),
                  b = c(50, 60, 70, 20, 90, 110, 30, 100))

# basic polar bar plot
gg1 <- ggplot(df1, aes(x = a, y = b, fill = a)) + 
  geom_bar(width = 1, stat="identity") +
  coord_polar()

# Accepted answer, it is rotating not curving
# set the angles for each text
myAng <- seq(-20, -340, length.out = 8)
# then update theme with angle
gg1 +
  theme(axis.text.x = element_text(size = 12, angle = myAng)) 

Accepted answer just rotates the text, if the text is short then rotation would be enough, but with long text it could be better to curve, possible?

3 Likes

You might want to look at Circular Visualization in R by Zuguang Gu.
The text section seems to have a few different methods that would fit the bill for you!

4 Likes

This would be a great post (and answer!) to have over at Stack Overflow.

The benefit of posting specific code questions at Stack Overflow is that more people are likely to benefit from the answers when you post there.

1 Like

The question is already on SO, see comments, but accepted answer is just rotating the text, not curving.

zx8754: Accepted solution is rotation... Did you manage to actually curve the text?
nejc-galof: No. The answer is the closest one solution.

Great, I have been through that package, was checking these examples, didn't see the cookbook, thank you. Will try to adopt and maybe add answer at SO.

Looking at the code for coord_polar(), it seems like it only affects geom positioning. That's probably for the best: although curved text sounds like a great idea, I'd imagine most other geoms (like lines and points) you wouldn't want to size or curve around the axis. It could lead to even more perceptual problems than polar plots already have :confused:

Lines do get curved though.

Did anyone ever find a gg_ based solution to this? I have the same problem.

There are two packages that purport to do it, circlize and plotrix. Both of them make R base graphics that are then hard to combine with ggplots (especially if you want to output as SVG). In addition, neither of them support plotmath expressions in text.

I put a feature request for this on the ggplot2 github issues. If anyone has a better solution, I'd appreciate it.

Just posting the related feature request you filed here, @amos, since it will allow others to keep track of the progress/any updates:

1 Like