I have a dataframe df like this one:
Id Var1 Var2 Var3
001 yes no yes
002 no no yes
003 yes yes no
I want to create a barplot with 3 bars that represents proportions of yesand nofor Var1 Var2 Var3. Is it possible to do that with ggplotwithout reshaping the dataframe?
Thank you,
corrado
As it was already mentioned it is better to reshape data.
But if you need to use original data frame then you should use
geom_bar()for each column you want to appear on plot. Ingeom_bar()you should providexvalues that will separate those bars – I used variable names as characters.fill=andposition="stack"ensures that bars are stacked.y=(..count..)/sum(..count..))will calculate proportions.