分享

R画dumbbell chart及代码

 terminator_523 2019-12-02

我们在想要展示我们的科研成果的时候经常会需要用到一些图,其中dumbbell chart也是我们常用图之一,dumbbell看起来复杂,但是也是可以用R画的,代码如下:

library(ggplot2)library(ggalt)theme_set(theme_classic())
health <- read.csv('https://raw./selva86/datasets/master/health.csv')health$Area <- factor(health$Area, levels=as.character(health$Area)) # for right ordering of the dumbells
# health$Area <- factor(health$Area)gg <- ggplot(health, aes(x=pct_2013, xend=pct_2014, y=Area, group=Area)) +        geom_dumbbell(color='red', size=0.75)+ scale_x_continuous(label=percent) + labs(x=NULL, y=NULL, title='Dumbbell Chart', subtitle='Pct Change: 2013 vs 2014', caption='Source: https://github.com/hrbrmstr/ggalt') + theme(plot.title = element_text(hjust=0.5, face='bold'), plot.background=element_rect(fill='#f7f7f7'), panel.background=element_rect(fill='#f7f7f7'), panel.grid.minor=element_blank(), panel.grid.major.y=element_blank(), panel.grid.major.x=element_line(), axis.ticks=element_blank(), legend.position='top', panel.border=element_blank())plot(gg)

最终结果图如下所示:

看起来很长的代码,其实很多都是固定的用法,适用于多种做图,学会了一个,那么做其他图时也可以用到。先把R常用的图介绍完后,给大家介绍一些比较常用的固定用法。

恭喜你,又学到了一个新技能。有任何问题,欢迎留言。

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多