我们在想要展示我们的科研成果的时候经常会需要用到一些图,其中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常用的图介绍完后,给大家介绍一些比较常用的固定用法。 恭喜你,又学到了一个新技能。有任何问题,欢迎留言。 |
|
来自: terminator_523 > 《生物信息学技能》