How can I add legend to this plot.
My code is as follows :
d1 = densCols(data4$x, data4$y,
colramp = colorRampPalette(c("navy blue","yellow","firebrick","firebrick"),
space = "Lab"))
ggplot(data4) +
geom_point(aes(x=x, y= y, col = d1), size = 0.1) +
scale_color_identity() +
theme_bw() +
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) +
labs(x="xaxis", y="yaxis", title="xyz cells") +
theme(plot.title = element_text(hjust = 0.5))
theme(legend.position=c(1,1),legend.justification=c(1,1))
I tried this and various other things mentioned but don't know why it is not working.
Thanks a lot for the help in advance.
Ok after adding scale_color_identity(guide = "legend"). My graph looks something like this