Bar plot with multiple factors

Hi, there. I am having some problems with a bar plot with multiple factors. One of them has a higher frequency, but since it is the one with less data, the bars were plotted according to the size of its data and not to the frequency. How can I solve it?
I am using the code below:
ndat5 %>%
ggplot(aes(x = Person, y = Frequency, fill = SPE)) +
geom_bar(stat = "identity", color = "grey", position = position_dodge()) +
geom_text(aes(label = Percent),
vjust= -0.25,
position = position_dodge(0.9)) +
theme(legend.position = "top") +
theme_light()

thanks for the code but can you supply some sample data as well?

A handy way to supply sample data is to use the dput() function. See ?dput. If you have a very large data set then something like head(dput(myfile), 100) will likely supply enough data for us to work with.

I'm not sure that understand you correctly, but maybe you just need to use geom_col() instead of geom_bar() and set y = Percent:

ndat5 %>%
ggplot(aes(x = Person, y = Percent, fill = SPE)) +
geom_col(stat = "identity", color = "grey", position = position_dodge()) +
geom_text(aes(label = Percent),
vjust= -0.25,
position = position_dodge(0.9)) +
theme(legend.position = "top") +
theme_light()
1 Like

That's exactly what I was trying to do. Thank you very much.

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.