R-ggplot2:坐标雷达不使用geom rect或注释(';rect';)
我正在处理这里讨论过的一个类似问题: 和 我想要一条带有R-ggplot2:坐标雷达不使用geom rect或注释(';rect';),r,ggplot2,R,Ggplot2,我正在处理这里讨论过的一个类似问题: 和 我想要一条带有coord_polar的直线,而ggiraphExtra软件包中的coord_radar()功能几乎让我达到了我想要的目的,也就是说(从之前的回复中,请参见上面的链接2) 但是,我想使用注释('rect')(或geom_矩形)为这个图添加背景色;但当我这样做的时候: iris %>% gather(dim, val, -Species) %>% group_by(dim, Species) %>% summar
coord_polar
的直线,而ggiraphExtra
软件包中的coord_radar()
功能几乎让我达到了我想要的目的,也就是说(从之前的回复中,请参见上面的链接2)
但是,我想使用注释('rect')(或geom_矩形)为这个图添加背景色;但当我这样做的时候:
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()
我收到以下错误消息:
“`$中的
错误我不知道错误是从哪里来的,我认为这不容易调试。但是,为什么不直接使用多边形:
p <- iris %>% gather(dim, val, -Species) %>%
group_by(dim, Species) %>% summarise(val = mean(val)) %>%
ggplot(aes(dim, val, group=Species, col=Species))
annotPolar <- list(
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"),
coord_polar()
)
lst <- list(
p +
geom_polygon(size=2, fill=NA, show.legend = F) +
geom_line(size = NA) +
guides(color = guide_legend(override.aes = list(size = 2))) +
annotPolar +
ggtitle("polygon"),
p +
geom_line(size=2) +
annotPolar +
ggtitle("line"),
p +
geom_line(size=2) +
ggiraphExtra:::coord_radar() +
ggtitle("radar")
)
gridExtra::grid.arrange(grobs=lst, ncol = 2)
p%聚集(昏暗,山谷,-物种)%>%
分组依据(dim,物种)%>%总结(val=平均值(val))%>%
ggplot(aes(dim、val、组=种、列=种))
annotPolar我不知道错误来自何处,我认为这不容易调试。但是,为什么不直接使用多边形:
p <- iris %>% gather(dim, val, -Species) %>%
group_by(dim, Species) %>% summarise(val = mean(val)) %>%
ggplot(aes(dim, val, group=Species, col=Species))
annotPolar <- list(
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"),
coord_polar()
)
lst <- list(
p +
geom_polygon(size=2, fill=NA, show.legend = F) +
geom_line(size = NA) +
guides(color = guide_legend(override.aes = list(size = 2))) +
annotPolar +
ggtitle("polygon"),
p +
geom_line(size=2) +
annotPolar +
ggtitle("line"),
p +
geom_line(size=2) +
ggiraphExtra:::coord_radar() +
ggtitle("radar")
)
gridExtra::grid.arrange(grobs=lst, ncol = 2)
p%聚集(昏暗,山谷,-物种)%>%
分组依据(dim,物种)%>%总结(val=平均值(val))%>%
ggplot(aes(dim、val、组=种、列=种))
谢谢,它确实很好用。我不完全明白为什么多边形可以工作,但直线不行。谢谢,它确实工作得很好。我不能完全理解为什么多边形可以工作,但直线不行。