I am in a bit of a struggle and I can't find a solution (it should be very simple) my Code is this
df Ch1 V1 V2 ID A a1 a2 1 B b1 b2 2 C a1 b2 1 D d1 d2 3 ... in total we have values ranging from 1 to 9. I simply want to plot how often 1(,2,3,...,9) occurs in this data frame. My code is this
ggplot(df,aes(ID))+ #because I read that leaving y value makes ggplot count the occurences which is T geom_bar()+ This works but unfortunately I get this as a result
I want all values to be displayed though. I tried to modify this with scale_x_continuous but it didn't work (made the whole x-axis go away and display only 1)
I know I can also create a table = table(df)
But I want to find a universal solution. Because later I want to be able to apply this while making several bars per x-axis value with dependency on V1 or V2 ...
Thank you very much for your help!



ggplot(data=df%>% gather(Variable, ID, -V1), aes(x = factor(reorder(V1,-ID)), fill = Variable))fill = V1to the aesthetic. You shouldn't need to reshape your data.ggplot(df, aes(x = ID, fill = V1)) + geom_bar()The bars are stacked by default - if you don't want this usegeom_bar(position = "dodge").