0

what is wrong my code that does not change the filling color?

cars %>%
  ggplot() + 
  geom_point(aes(x = speed, y = dist,
                 color= I(ifelse(dist >50, 'red', 'black')),
                 fill= I(ifelse(dist >50, 'pink', 'gray'))
                 
                 )
             
             )

enter image description here

Mathica
  • 1,241
  • 1
  • 5
  • 17

1 Answers1

2

You need to have a point shape that allows both fill and colour.

library(ggplot2)
cars %>%
    ggplot() + 
    geom_point(
        aes(x = speed, y = dist,
            color= I(ifelse(dist >50, 'red', 'black')),
            fill= I(ifelse(dist >50, 'pink', 'gray')), 
        ), 
        shape = 21, 
        size = 4 # changing size so it's easy to visualise
    )

enter image description here

To check point shapes that allow both fill and colour use help(points) and refer to the 'pch' values section

AdroMine
  • 1,427
  • 5
  • 9