I am trying to plot a scatterdiagram x, y coloured by a factor z (five values) with the colour values assigned by a palette I have tried :
library(ggplot2)
Palette1 <- c('red','green','blue','violet','black')
p <- ggplot(df1, aes(x,y))
p + geom_point(aes(colour = factor(z)))
p + scale_colour_manual(values=Palette1 )
but I get an error message:
Error: No layers in plot
Thank you for your help.
The error comes because you plot:
And then try to make a new plot of:
Which doesn't have any layers in it. Instead, I usually make all my assignments at the time of plotting:
Or you can assign your first
p + geom_point(...)
top
:Then proceed as you were.