Нарисуйте три четверти круга в ggplot2 со стрелкой и надписью - PullRequest
1 голос
/ 24 апреля 2019

Я хочу нарисовать три четверти круга в ggplot2 со стрелками и метками. Используя ggplot2 и ggforce, я нашел что-то, что работает, но это кажется чрезвычайно сложным.

Есть ли более простые варианты для достижения того, чего я хочу?


df <- data.frame(x = 100, y = 100, label = "R")

library(ggplot2)
library(ggforce)

r <- 10

ggplot(df) + 
  geom_circle(aes(x0 = x, y0 = y, r = r)) +
  geom_rect(aes(xmin = x, ymin = y, xmax = x + r + 1, ymax = x + r + 1), 
            fill = "white") +
  geom_segment(aes(x = x + r, y = y, xend = x + r, yend = y + 1), 
               arrow = arrow()) +
  annotate("text", x = df$x, y = df$y, label = df$label) + 
  theme_void()

enter image description here

1 Ответ

2 голосов
/ 24 апреля 2019

Будет ли это считаться проще?

ggplot(df) + 
  geom_arc(aes(x0 = x, y0 = y, r = r,
               start = 0, end = -1.5 * pi),
           arrow = arrow()) + 
  annotate("text", x = df$x, y = df$y, label = df$label) + 
  theme_void()

# equivalent to above with geom_text instead; I'm not sure if your actual use
# case has preference for one or the other
ggplot(df) + 
  geom_arc(aes(x0 = x, y0 = y, r = r,
               start = 0, end = -1.5 * pi),
           arrow = arrow()) + 
  geom_text(aes(x = x, y = y, label = label)) + 
  theme_void()

plot

...