簡體   English   中英

用箭頭和標簽在“ ggplot2”中畫出四分之三圓

[英]Draw three-quarter-circle in `ggplot2` with arrow and label

我想在ggplot2中用箭頭和標簽畫出四分之三的圓。 使用ggplot2ggforce我發現了一些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()

在此處輸入圖片說明

這樣認為會更簡單嗎?

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()

情節

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM