I'm stumped as to why my points are incorrectly coloured. I have set my own colour palette and used this to define the colours of the geom_point() but the colours that are actually being plotted are incorrect.
colfunc <- colorRampPalette(c("black", "#FFAFAF"))
plot(rep(1,41), col=colfunc(41), pch=19, cex=3)
cols <- colfunc(41)
df$cols <- cols[df$num]
baseMap <- ggplot(data = world) +
geom_sf(color = "black", fill = "grey") +
geom_point(data = df,
mapping = aes(x = lon, y = lat, col = cols[num])) +
xlab("Longitude") + ylab("Latitude")
baseMap
The colour palette I have created looks like this:
But this is resulting in the following colours:
Why aren't these colours matching??
Thanks
I have tried numerous different ways of setting the aes() but can't work out why the colours don't match
You need
scale_colour_manual()
or similar. We do not have yourdf
. This is an example based on anotherdf
:Created on 2023-11-18 with reprex v2.0.2