【发布时间】:2017-05-25 10:04:43
【问题描述】:
我正在处理此处讨论过的类似问题: ggplot - connecting points in polar coordinates with a straight line 和 ggplot2: connecting points in polar coordinates with a straight line 2
我想要与coord_polar 和ggiraphExtra 包中的函数coord_radar() 成直线,这几乎让我到达了我想要的位置,即(来自之前的回复,请参见上面的链接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()
但是,我想使用 annotate('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
任何见解都将不胜感激。抱歉,如果这在其他地方得到解决,我很确定我已经查看了有关该主题的所有问题。 谢谢
【问题讨论】: