Side-by-side bars in bar plot

后端 未结 1 1409
礼貌的吻别
礼貌的吻别 2021-01-29 06:27

This is based on this post. Suppose that I have this data:

y = data.frame(Specie=c(\'A\',\'V\',\'R\',\'P\',\'O\'),Number=c(18756,8608,3350,3312,1627))
z = data.         


        
相关标签:
1条回答
  • 2021-01-29 07:01
    y = data.frame(Specie=c('A','V','R','P','O'),Number=c(18756,8608,3350,3312,1627))
    z = data.frame(Specie=c('A','V','R','P','O'),Number=c(17000,1000,8000,5500,9000))
    
    library("ggplot2")
    library("reshape2")
    
    df=merge(y,z,by=c("Specie"))
    names(df)=c("Specie","y","z")
    
    df=melt(df)
    
    ggplot(df,aes(x=Specie,y=value,fill=variable))+geom_bar( stat="identity",position=position_dodge())
    

    enter image description here

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