Making an arc in ggplot2()

I need to make a width red quarter circle using ggplot2.
My best attempt was using ggforce:geom_arc2() but it is not perfect.

  1. It is not the same width for the whole arc. Strange.
  2. I would rather use pure ggplot2()

    Here are my code:
library(ggforce)
library(ggplot2)

l1 <- data.frame(x = c(0,50), y = c(30,30))
l2 <- data.frame(x = c(0,50), y = c(50,50))
l3 <- data.frame(x = c(30,30), y = c(0,50))
l4 <- data.frame(x = c(50,50), y = c(0,50))
a1 <- data.frame(x0 = 0, y0 = 0, r0 = 0, r = 40, angle = c(0, pi/2))

g <- ggplot()
g <- g + geom_arc2(data = a1, size = 80, color = "red",
                   aes(x0 = 0, y0 = 0, r = r, end = angle))
g <- g + geom_path(data = l1, aes(x,y))
g <- g + geom_path(data = l2, aes(x,y))
g <- g + geom_path(data = l3, aes(x,y))
g <- g + geom_path(data = l4, aes(x,y))
g <- g + coord_cartesian(expand = FALSE, xlim = c(-5, 55), ylim = c(-5, 55))
g

Have you tried using geom_curve?

If you expect it to be the same width throughout and it's not, then you might open an issue in ggforce. (I see you already did so, and I'm adding the link here so that anyone seeing this in the future can follow along.)

I could be wrong here, but: Thomas, the author of ggforce, is also one of the maintainers of ggplot2, which is to say that I'm guessing he wouldn't have added it to ggforce if it was already a geom in ggplot.
You could certainly implement your own ggproto object (see Extending ggplot2 for details), which is what Thomas is doing in ggforce.

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.