用ggplot2生成雷达图 [英] Generate radar charts with ggplot2

查看:446
本文介绍了用ggplot2生成雷达图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了简化可重复性,您可以在此处下载数据.其结构为:

In order to ease reproducibility, you can download here the data. Its structure is:

> str(data)
'data.frame':   30 obs. of  4 variables:
 $ Count: num  -15.26 NaN NaN -7.17 -49.37 ...
 $ X1   : Factor w/ 1 level "Mean": 1 1 1 1 1 1 1 1 1 1 ...
 $ X2   : Factor w/ 10 levels "DC1","DC10","DC2",..: 1 1 1 3 3 3 4 4 4 5 ...
 $ X3   : Factor w/ 3 levels "SAPvsSH","SAPvsTD6",..: 1 2 3 1 2 3 1 2 3 1 ...

我运行以下ggplot图表:

I run this ggplot chart:

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))

结果如下:

此图表示SH和TD6相对于SAP(这是水平的黑色线,分别为红色和绿色)和TD6相对于SH(在这种情况下,也由水平的黑色表示)之间的差异百分比线,但现在为蓝色).我使用了十个变量:DC1:DC10.

This chart represents the percentage of difference between SH and TD6 respect SAP (which is the horizontal black line, in colors red and green respectively), and between TD6 respect SH (which in this case is represented as well by the horizontal black line, but now in blue color). I employed ten variables: DC1:DC10.

我想将此图表转换为雷达图.我尝试使用ggradarggRadar,但未成功.像这样的东西会很棒:

I would like to transform this chart in a radar chart. I tried to use ggradar or ggRadar, but unsuccessfully. Something like this would be amazing:

水平黑色线应该是完美的圆形,就像上一幅图像中位于红线和蓝线之间的圆一样.理想情况下,DC1应该朝顺时针方向向北放置.

The horizontal black line should be perfectly circular, like the circle placed between both red and blue lines in the previous image. Ideally, DC1 should be placed northwards, going clock-wise.

有什么想法或建议吗?

Any idea or suggestion?

推荐答案

感谢@DJack,我在这里发布了添加+ coord_polar()的结果:

Thanks to @DJack, I post here the result adding + coord_polar():

这是最终代码:

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()

这篇关于用ggplot2生成雷达图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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