Skip to Content

R ggplot2 assigning colours to a factor

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 :

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.