Specific spaces between bars in a barplot - ggplot2 - R

前端 未结 3 1111
北海茫月
北海茫月 2020-12-19 11:07

I have a simple bargraph like the following

a<-data.frame(x=c(\"total\",\"male\",\"female\",\"low education\",
            \"mid education\",\"high educ         


        
3条回答
  •  我在风中等你
    2020-12-19 11:34

    a<-data.frame(x=c("total","male","female","low education","mid education","high education","working","not working"),y=c(80,30,50,20,40,20,65,35))
    a$x<-as.character(a$x)
    a$x<-factor(a$x,levels=unique(a$x))
    
    a$rel = c("a", "a", "a", "b", "b", "b", "c", "c") # set groups
    ggplot(a, aes(rel, y, fill = factor(x))) + 
      geom_bar(stat = "identity", width = 0.5, position = position_dodge(0.7))
    

提交回复
热议问题