0

I get stucked in a code trying to plot a points that must be visualized in blue for positive and red for negative numbers, as follow:

ggplot(BCG, aes( reorder(x = SHARE, desc(SHARE)), 
                     y = ATRATIVIDADE, color = CURSO))+
geom_point( size = log2(BCG$MARGEM),
        show.legend = FALSE) +

scale_color_manual(values = ifelse(BCG$MARGEM > 0, 'navy', 'firebrick')) +
geom_text_repel(label = BCG$MARGEM,
            size= 3,
            alpha = .9,
            show.legend = FALSE)

Houever, the plot shows positive numbers in red and vice-versa:

enter image description here

Someone, please, could explain waht I am doing wrong? I really will appreciate your help!

Best,

A

  • 1
    If you want to color your points based on the sign of `MARGEM` then map this variable on the `color` aes, i.e. do `ggplot (..., aes(..., color = MARGEM > 0)) + ... + scale_color_manual(values = c("firebrick", "navy))`. – stefan Jun 12 '23 at 21:06

0 Answers0