Museums and nature centers project

I am stuck at the Museums and nature centers project at step 7. That’s how far I’ve gone this far:

museum_stacked <- museums_df %>%
mutate(Region.Code…AAM. = factor(Region.Code…AAM.)) %>%
ggplot(museums_df, aes(x=Region.Code…AAM., fill=Is.Museum)) +


I am not sure how to incorporate the factor() argument.

Thanks for the help :slight_smile:

Hi, can you link to the exercise?

May be able to help out.

yes, I’m sorry, I forgot. Here’s the link:

1 Like

It’s been a couple of days, so I’m sorry if this is too late to be helpful.

One thing I see here is that you’re changing museums_df in the pipe and storing it as museum_stacked, but then you’re feeding ggplot the original museums_df data frame. I haven’t piped things directly into ggplot, but I assume it works like other pipes, and you don’t need to specify the data frame you’re referencing. If you take the museums_df argument out of the ggplot call, I think you’ll pipe in the museums_stacked data frame you’ve just created.

I believe factor() is a function, not a separate argument. Try this:
ggplot(aes(x = factor(Region.Code…AAM., fill = Is.Museum))
**Note that I didn’t specify a data frame because of your piping. Without the pipes, you’d just have museums.stacked as the first argument.

That tells R, even though the values of Region.Code…AAM. are numbers, treat the numbers as names and not as actual numbers.

Hope that helps.


thank you very much for the help. My code now looks like this:

museum_stacked <- ggplot(museums_df, aes(x = factor(Region.Code…AAM.), fill = Is.Museum)) +
geom_bar(stat = “identity”)

But it still won’t work. Can you spot the mistake?