ggplot柱状图

ggplot柱状图

library(ggplot2)

library(farcats)

data <- read.table("/Users/mingzhang/Documents/GS-consite/GS-FC.txt",header=T,sep="\t")

head(data)


#按照文件自有顺序排列X轴标签

data[,1] <- fct_inorder(data[,1])

ggplot(data=data,mapping = aes(x=Sample,y=GS,fill= Type))+geom_bar(stat="identity")+

#X轴标签旋转90度

  theme(axis.text.x = element_text(angle = 90, hjust = 0.5, vjust = 0.5))+

  theme(panel.grid.major=element_blank(),panel.grid.minor=element_blank())


#改进版

ggplot(data=data,mapping = aes(x=Sample,y=GS,fill= Type))+geom_bar(stat="identity")+

#theme_bw()要加在前面,否则会覆盖下一条坐标标签的修改

  ylim(c(0,20))+theme_bw()+

  theme(axis.text.x = element_text(angle = 45, hjust = 1, vjust = 1))+

  theme(panel.grid.major=element_blank(),panel.grid.minor=element_blank())


可以ggsave了

你可能感兴趣的:(ggplot柱状图)