(125条消息) 【ggplot】复杂柱状图:自定义颜色、标签、位置、坐标轴和主题Ryan_Yang的博客-CSDN博客_复杂柱状图
data
data.melt
data.melt <-
data %>%
mutate(group = paste0("Cluster", group)) %>%
# data.frame(row.names = 1) %>%
# as.matrix() %>%
melt()
library(ggplot2)
ggplot(data.melt, aes(x=variable,y=value, fill = variable)) +
geom_boxplot(col="#6a737b")+
facet_grid(.~factor(group, paste0("Cluster",c(0:8))))+ #分面
geom_jitter(col="#caccd1", pch=19,cex=0.1, position = position_jitter(0.2))+
theme_bw()+RotatedAxis()+
theme(panel.grid = element_blank(),
axis.text.x=element_text(angle=10,hjust = 1,vjust=0.5))+
labs(x=NULL,y=NULL,title = "")+
geom_boxplot(position=position_dodge(0),aes(color = factor(group)))+
NoLegend()+theme(plot.title = element_text(hjust = 0.5)) #也就加上这一行,标题居中
ggplot(data.melt, aes(x=variable,y=value, fill = variable)) +
geom_bar(col="#6a737b",stat="identity")+#stat=”“identity”:指定了柱状图的高度(y)
facet_grid(.~factor(group, paste0("cluster.",c(0:8))))+#修改柱形图的顺序
scale_fill_manual(values=c('#1aafd0','#6a67ce','#ffb900','#fc636b'))+ #颜色
theme_bw() +#去除背景色
theme(panel.grid=element_blank()) #去除网格线