R Studio does not display colors other than Pink , any suggestions ?

R Studio does not display the specified colors despite what has been input, it only displays pink.

ggplot(data=penguins, aes(x=species,fill="green")) + geom_bar()

The above-linked picture is the output of the code above that, where I have set the color to "green" but it still displays pink.

Move fill = "green" outside of the aes() function.

I also tend to shift aes() and other parameters into the specific layer to which they apply, rather than the ggplot() call:

ggplot(data = penguins) +
  geom_bar(aes(x = species), 
           fill = "green")
1 Like

That actually worked and thank you ill make sure I assign aes () to the specific functions instead of ggplot() !!

I'm glad it worked for you!

Just to be clear: in this case you can use aes() and fill in ggplot(). The key difference is really that fill goes outside of aes() when you want to assign a single color to your data .

This should still work:

ggplot(data = penguins, aes(x = species), fill = "green") + geom_bar()

When plots get more complicated, with multiple layers, I've found it helpful to assign aes() per layer (as I showed above), so I've gotten in the habit of splitting them out.

If you want to assign colors based on the data itself, then you should place fill inside aes(), and point to a column:

ggplot(data = penguins) +
  geom_bar(aes(x = species,
               fill = island))

Happy plotting!

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.