(125條消息) 【ggplot】復(fù)雜柱狀圖:自定義顏色刁绒、標(biāo)簽冈欢、位置失仁、坐標(biāo)軸和主題Ryan_Yang的博客-CSDN博客_復(fù)雜柱狀圖
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)) #也就加上這一行,標(biāo)題居中
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()) #去除網(wǎng)格線