gpt4 book ai didi

r - 使用 ggplot2 中的 geom_area() 为雷达图中的区域着色

转载 作者:行者123 更新时间:2023-12-05 00:48:04 29 4
gpt4 key购买 nike

在继续阅读之前,建议您下载并查看this question posted in this forum 中的原始代码。 .

我运行这个 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) +

并得到了这个情节:

enter image description here

正如您想象的那样,代码有问题。蓝色组似乎正确着色。我想为所有组着色,以黑色斜线环为引用,代表 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 由 reprex package (v0.2.0)。

关于r - 使用 ggplot2 中的 geom_area() 为雷达图中的区域着色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50356147/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com