0

I'm a new R Studio User (I've only used this for several months). I love it! I got this table where I'm comparing two poets vocabulary. I would like them to have a different color each one. I tried to change the values but had no luck. Here is my code and my results. Could you give me a hint about how could I improve this? Thank you in advance!!!

# 50 sustantivos más frecuentes
Poemas_Analizado %>%
 group_by(poeta) %>%
 filter(upos == "NOUN") %>%
 count(lema, sort = T) %>%
 mutate(lema = reorder(lema, n)) %>%
 top_n(50) %>%
 ggplot(aes(reorder(lema, n),n)) +
   geom_col(fill = "greenyellow") +
   coord_flip() +
   facet_wrap(~poeta, scales = "free_y")

enter image description here

Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
  • Hi and welcome to Stack Overflow! It's generally difficult to answer a question without a subset of the data you're working with so that others can try to produce the graph on their own and test their solutions. Providing the output of something like `dput(head(Poemas_Analizado, 20))` would probably give us enough of the data to work with. See [mcve](https://stackoverflow.com/help/minimal-reproducible-example) for more details on how to provide good examples. – phalteman Sep 13 '21 at 23:53
  • Please trim your code to make it easier to find your problem. Follow these guidelines to create a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). – Community Sep 14 '21 at 01:51
  • Glad it did the trick for you. The best way to signal to others that it solved your problem is to mark the answer correct (using the green checkmark) and to upvote the answer if you think it was especially helpful. – phalteman Sep 14 '21 at 17:13

1 Answers1

0

Try replacing the call to ggplot() at the end of your code with this:

ggplot(aes(reorder(lema, n),n)) +
   geom_col(aes(fill = poeta)) +
   coord_flip() +
   facet_wrap(~poeta, scales = "free_y")

This will tell ggplot that you want the fill of the columns to change with different values of poeta, rather than to be all "greenyellow" as you've specified.

phalteman
  • 3,442
  • 1
  • 29
  • 46