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'))
)
)
>Solution :
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
)
To check point shapes that allow both fill and colour use help(points) and refer to the ‘pch’ values section

