我与已经在这里讨论了类似的问题,工作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你
谢谢你,它工作得很好确实如此。我不完全确定要理解为什么多边形可行,但行不行。 –