在继续阅读之前,我建议您下载并查看原始代码这个问题发布在这个论坛 https://stackoverflow.com/questions/50353923/generate-radar-charts-with-ggplot2?noredirect=1#comment87724216_50353923.
我运行这个 ggplot 代码:
ggplot(data=data, aes(x=X2, y=Count, group=X3, colour=X3)) +
geom_point(size=5) +
geom_line() +
xlab("Decils") +
ylab("% difference in nº Pk") +
ylim(-50,25) + ggtitle("CL") +
geom_hline(aes(yintercept=0), lwd=1, lty=2) +
scale_x_discrete(limits=c(orden_deciles)) +
coord_polar() +
geom_area(aes(color=X3, fill=X3), alpha=0.2) +
并得到了这个情节:
正如您可能想象的那样,代码有问题。蓝色组似乎着色正确。我想为所有组着色,以代表 0 的黑色斜线环为参考。
我怎样才能实现这个?
geom_area()
有一个默认值position
的论证stack
。这会将每个区域堆叠在其他区域之上,在这种情况下会产生奇怪的结果。
只需将位置更改为identity
:
library(ggplot2)
## This was not given, I supposed it's in this form
orden_deciles <- paste0('DC', 1:10)
ggplot(data=data, aes(x=X2, y=Count, group=X3, colour=X3)) +
geom_point(size=5) +
geom_line() +
xlab("Decils") +
ylab("% difference in nº Pk") +
ylim(-50,25) + ggtitle("CL") +
geom_hline(aes(yintercept=0), lwd=1, lty=2) +
scale_x_discrete(limits=c(orden_deciles)) +
geom_area(aes(fill=X3), alpha=0.2, position = position_identity()) +
coord_polar()
#> Warning: Removed 5 rows containing missing values (geom_point).
#> Warning: Removed 2 rows containing missing values (geom_path).
创建于 2018-05-15代表包 http://reprex.tidyverse.org(v0.2.0)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)