Create histogram by group

I want to create an histogram by group.
I have tried the code but getting the error message "unexpected system in"

ggplot(df, aes(x="maize_acres", fill="group ", color="group"))+
geom_histogram,(position="identity")

Screenshots are not easy for people to use to help you. Please try to share your data in one of these methods listed in here: FAQ: How to do a minimal reproducible example ( reprex ) for beginners For example, you could do something like this dput(head(df, 50)) to show the first 50 rows and share that with us.

In the mean time, it's good to know two things that might help your code.

  1. R is case-sensitive so instead of using group, you should use Group
  2. Is there an underscore in maize_acres, it doesn't appear so from the screenshot but hard to know until you share data that is easier to use
  3. You don't need to quote the variables and it would instead be something like this:
ggplot(df, aes(x=maize_acres, fill=Group, color=Group))+
    geom_histogram,(position="identity")
  1. If the first variable has a space in it, you need to refer to it in back ticks like this:
ggplot(df, aes(x=`Maize acres`, fill=Group, color=Group))+
    geom_histogram,(position="identity")

Also, there is a comma that shouldn't be there, between "geom_histogram" and the opening parentheses.

1 Like

This topic was automatically closed 21 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.