library(tidyverse)
<-data.frame(month=rep(month.abb,each=3),class=c('A','B',"C"),value=runif(36))
dfhead(df)
数据准备
ggplot(data=df,aes(x=month,weight=value,fill=class))+
geom_bar(position = 'stack')
ggplot(data=df,aes(x=month,y=value,fill=class))+
geom_col(position = 'stack')
ggplot(data=df,aes(x=month,weight=value,fill=class))+
geom_bar(position="dodge")
ggplot(data=df,aes(x=month,weight=value,fill=class))+
geom_bar()
有序列表
.2 <- df %>%
dfmutate(month=ordered(month,levels=month.abb),
class=ordered(class,levels=c("A","B","C")))
<-ggplot(df.2,aes(month,value,fill=class))+
pgeom_col()
p
样式修改
+theme_classic()+
pscale_fill_brewer(palette = "Set1")
library(RColorBrewer)
display.brewer.all()