查看原文
其他

跟着Nature学绘图——不一样的条形图!

王志山 科研后花园 2023-09-08

 

点击上方

“科研后花园”

关注我们

代码如下:

1、设置工作环境并加载所需R包:

#设置工作环境rm(list=ls())setwd("D:/条形图")
#加载包library(ggplot2) # Create Elegant Data Visualisations Using the Grammar of Graphics

2、加载数据:

#加载数据df <- read.table("data.txt",header = T, check.names = F)

3、绘图:

col <- c("#d91481","#e7524e","#f8a250","#f9f05f","#4ea363","#7bc8f6","#5193f4","#ae77e8")ggplot(df,aes(samples,value,fill=group))+ geom_bar(stat="summary",fun=mean,position="dodge")+ theme_classic()+ theme(axis.text.x=element_blank(), axis.text.y=element_text(color='black',size=9), axis.ticks.x = element_blank(), legend.text = element_text(color='black',size=12), legend.title = element_blank(), legend.background = element_blank(), legend.position = c(0.5,0.9), axis.title = element_text(color='black',size=12))+ scale_y_continuous(expand = c(0, 0), limit = c(0, 100))+ scale_x_continuous(expand = c(0, 0.5), limit = c(0, 125))+ scale_fill_manual(values = col)+ labs(x="Genome assembly",y="Number of duplicated \nprotein-coding genes")+  guides(fill = guide_legend(nrow = 1))

4、总代码如下:

#设置工作环境rm(list=ls())setwd("D:/条形图")
#加载包library(ggplot2) # Create Elegant Data Visualisations Using the Grammar of Graphics
#加载数据df <- read.table("data.txt",header = T, check.names = F)
#绘图col <- c("#d91481","#e7524e","#f8a250","#f9f05f","#4ea363","#7bc8f6","#5193f4","#ae77e8")ggplot(df,aes(samples,value,fill=group))+ geom_bar(stat="summary",fun=mean,position="dodge")+ theme_classic()+ theme(axis.text.x=element_blank(), axis.text.y=element_text(color='black',size=9), axis.ticks.x = element_blank(), legend.text = element_text(color='black',size=12), legend.title = element_blank(), legend.background = element_blank(), legend.position = c(0.5,0.9), axis.title = element_text(color='black',size=12))+ scale_y_continuous(expand = c(0, 0), limit = c(0, 100))+ scale_x_continuous(expand = c(0, 0.5), limit = c(0, 125))+ scale_fill_manual(values = col)+ labs(x="Genome assembly",y="Number of duplicated \nprotein-coding genes")+ guides(fill = guide_legend(nrow = 1))

温馨提示

如果你喜欢本文,请分享到朋友圈,想要获得更多信息,请关注我。





您可能也对以下帖子感兴趣

文章有问题?点此查看未经处理的缓存