使用ggplot2中的geom_area()在雷达图中的色彩区域 [英] Color areas in a radar chart using geom_area() in ggplot2

查看:146
本文介绍了使用ggplot2中的geom_area()在雷达图中的色彩区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在阅读之前,建议您下载并查看

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆