我與已經在這裏討論了類似的問題,工作geom_rect或註釋(「矩形」)工作: ggplot - connecting points in polar coordinates with a straight line 和 ggplot2: connecting points in polar coordinates with a straight line 2的R - GGPLOT2:coord_radar不
我想直線與coord_polar
和功能coord_radar()
從ggiraphExtra
包差點被我在哪裏,我想是的,即(從以前的響應見上面的鏈接2)
iris %>% gather(dim, val, -Species) %>%
group_by(dim, Species) %>% summarise(val = mean(val)) %>%
ggplot(aes(dim, val, group=Species, col=Species)) +
geom_line(size=2) + ggiraphExtra:::coord_radar()
不過,我想背景顏色添加到該PL使用註釋('rect')(或geom_rectangle);但是當我做:
iris %>% gather(dim, val, -Species) %>%
group_by(dim, Species) %>% summarise(val = mean(val)) %>%
ggplot(aes(dim, val, group=Species, col=Species)) +
geom_line(size=2) +
annotate("rect", xmin=0, xmax =2.5 , ymin = -Inf, ymax = Inf, alpha=0.3, fill="#C77CFF")+
annotate("rect", xmin=2.5, xmax =4.5 , ymin = -Inf, ymax = Inf, alpha=0.3, fill="#619CFF")+
ggiraphExtra:::coord_radar()
我收到以下錯誤信息: Error in ``$<-.data.frame
(*tmp*``, "r", value = numeric(0)) : replacement has 0 rows, data has 1
此錯誤是有點晦澀給我,我不知道怎麼用它做注意。相同的代碼與coord_polar
作品就好在這裏看到: polar coord with coloured background
任何見解將不勝感激道歉,如果這解決了別的地方,我敢肯定,我查看了有關此主題的所有問題 比。 k你
謝謝你,它工作得很好確實如此。我不完全確定要理解爲什麼多邊形可行,但行不行。 –