color the y axis variables with different colors

I'm sorry, it's because I'm a beginner in R's and I still need help with more basic things.

How could I color each genus with different colors of the y-axis variables? Thanks for the help.

This is my graph:

I used this code:

>data$Espécie <- factor(data$Espécie, levels = c("Mycteroperca tigris","Paralabrax nebulifer","Mycteroperca xenarcha","Mycteroperca prionura","Mycteroperca jordani","Epinephelus guttatus","Mycteroperca olfax","Mycteroperca venenosa","Mycteroperca bonaci","Dermatolepis dermatolepis","Alphestes afer","Paralabrax clathratus","Epinephelus striatus","Paranthias colonus","Mycteroperca rosacea","Epinephelus polyphekadion","Epinephelus ongus","Epinephelus marginatus","Epinephelus itajara","Epinephelus fuscoguttatus","Plectropomus maculatus","Plectropomus leopardus","Plectropomus areolatus"))
>ggplot(data, aes(x = Espécie, y = Profundidade)) + 
         geom_boxplot(outlier.colour="red", outlier.shape=8,
                      outlier.size=2, notch=FALSE) + coord_flip() + theme_classic() + labs(title = "Epinephelidae", x = "Espécies", y = "Profundidade")

It's not clear what you mean by " colors of the y-axis variables" but if you are trying to change the color of the boxes by especies, then add the fill aesthetic.

ggplot(data, aes(x = Espécie, y = Profundidades, fill = Espécie)) +
1 Like

in fact I created another column in the worksheet (gender) and I put fill = gender and it worked. Thanks

This would be hard to guess since you haven't provided sample data, the next time please make a reproducible example.

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.