ggplot 条形图(geom_bar)
设置x坐标轴样本顺序及修改fill的颜色,利用scale_x_discrete和scale_fill_manual函数
library(ggplot2)
data <- data.frame(Class=c(rep('A',20),rep('B',30),rep('C',50),rep('D',60)))
ggplot()+geom_bar(data=data,aes(x=Class,fill=Class),stat = 'count',width = 0.6)+
theme(
axis.text.y=element_text(size=10,colour = "black"),
axis.text.x=element_text(size=10,colour = "black"),
axis.title.y = element_text(colour = "black",size=12,vjust = 0.5,hjust = 0.5,angle=90),
plot.title = element_text(colour = "black",size=20,vjust = 0.5,hjust = 0.5,angle=0),
axis.title.x = element_text(colour = "black",size=12,vjust = 0.5,hjust = 0.5),
legend.text = element_text(size=12),
axis.line = element_line(size=0.6),
axis.ticks = element_line(size=0.6),
axis.ticks.length = unit(2,'mm'),
legend.title = element_blank(),
panel.background = element_blank())+
scale_x_discrete(limits = c("D","C","B","A"))+ # change the oreder of the x axis
scale_fill_manual(values = c(rgb(0,157,237,max=255),rgb(149,0,128,max=255),rgb(255,128,0,max=255),rgb(0,170,48,max=255)))