使用ggplot2中的geom_area()在雷达图中的色彩区域 [英] Color areas in a radar chart using geom_area() in ggplot2
问题描述
Before reading any longer, I suggest you to download and see the original codes in this question posted in this forum.
我运行以下ggplot代码:
I run this ggplot code:
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.
As you may imagine, something's wrong with the code. Blue group seems to be colored properly. I would like to color all the groups, taking as reference the black-slashed ring, which represent 0.
我该如何实现?
推荐答案
geom_area()
的默认position
参数为stack
.这样会将每个区域叠加在其他区域上,在这种情况下会产生怪异的结果.
geom_area()
has a default position
argument of stack
. This stack each area over the others, creating weird results in this case.
只需将位置更改为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).
由 reprex软件包(v0.2.0)创建于2018-05-15.
Created on 2018-05-15 by the reprex package (v0.2.0).
这篇关于使用ggplot2中的geom_area()在雷达图中的色彩区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!