Grouped bar plot column width uneven due to no data

后端 未结 2 971
孤街浪徒
孤街浪徒 2021-01-24 00:29

I am trying to display a grouped bar plot for my dataset, however, due to some months have no data (no income), the column width is showing up as unequal and I was hoping to hav

2条回答
  •  情话喂你
    2021-01-24 01:18

    You are looking for position_dodge2(preserve = "single")(https://ggplot2.tidyverse.org/reference/position_dodge.html).

    library(ggplot2)
    plot = ggplot(Checkouts, aes(fill = State, x = Month, y= Income)) + 
      geom_bar(colour = "black", stat = "identity", 
               position = position_dodge2(preserve = "single")) 
    

    Also, you don't need to specify the columns to the data frame with $ in ggplot(). For example, Checkouts$State can be replaced with State.

提交回复
热议问题