ggplot multiple grouping bar

前端 未结 2 1805
逝去的感伤
逝去的感伤 2020-12-02 16:16

I would like to know how to get 9 grouping bar plot (3x3) togheter.

My CSV : data <- read.csv(\"http://pastebin.com/raw.php?i=6pArn8GL\", sep = \";\")

相关标签:
2条回答
  • 2020-12-02 16:54

    Using @Didzis reshaped data , here a lattice version:

    barchart(value~variable|Type,
             groups=Annee,data=df.long,layout=c(3,3),
             between=list(3,3),
             axis=axis.grid,
             auto.key=TRUE)
    

    enter image description here

    0 讨论(0)
  • 2020-12-02 16:59

    First, reshape your data from wide to long format.

    library(reshape2)
    df.long<-melt(df,id.vars=c("ID","Type","Annee"))
    

    Next, as during importing data letter X is added to variable names starting with number, remove it with substring().

    df.long$variable<-substring(df.long$variable,2)
    

    Now use variable as x, value as y, Annee for fill and geom_bar() to get barplot. With facet_wrap() you can split data by Type.

    ggplot(df.long,aes(variable,value,fill=as.factor(Annee)))+
       geom_bar(position="dodge",stat="identity")+
       facet_wrap(~Type,nrow=3)
    

    enter image description here

    0 讨论(0)
提交回复
热议问题