relative likelihood with ggplot

I'm trying to create a grouped barplot with ggplot. However, my variables are based on absolute likelihood and I would like to change them into relative likelihood since my two Groups have a different number of rows, so I can just compare them nicely if I have relative likelihoods respectively for both Groups.

This is my Code:

A <- Wahlcombined %>%
dplyr::select(Atomenergie, .origin) %>%
ggplot(aes(x = (Atomenergie), fill = .origin))

A + geom_bar(aes(y = (..count..)/sum(..count..))) +
ggtitle("Einstellung zur Atomenergie Häufigkeiten")+
ylab ("Häufigkeiten")+
xlab("für Atomenergie - gegen Atomenergie")+
labs(fill = "Bundestagswahl")

With (aes(y = (..count..)/sum(..count..))) I try to create relative likelihoods. I do not get an error, but it just does not create an barplot, it just Shows the title and the axis labels. It works without (aes(y = (..count..)/sum(..count..))) but then I just get absolute likelihoods and can't really compare the two Groups.

Any ideas?
Thank you very much!

I would encourage you in this, and more generally to specialise and separate your code into separate concerns. In this case it would mean preparing your data first and only then plotting it, rather than embedding on the fly calculations within your plotting code.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.