1

I am making a scatter plot with color coded density with this code :

d1 = densCols(newData_cut, 
          colramp = colorRampPalette(c("navy 
         blue","yellow","firebrick","firebrick"), 
                                     space = "Lab"))

ggplot(newData_cut) + 
   geom_point(aes(x=green, y= blue, col = d1), size = 1) +
   xlim(0, 0.4)+
   ylim(0,2)

But when I get the image it looks like this:

Can somebody help me to plot a proper legend with a color representing the count / density of the points?

> dput(head(newData_cut))
structure(list(green = c(0, 0.229804, 0, 0, 0, 0), blue = c(0.080264, 
0.204474, 0.04059, 0.040284, 0.042421, 0.041505), width = c(1317, 
4529, 1, 10, 23, 5)), .Names = c("green", "blue", "width"), row.names = 
c(NA, 
6L), class = "data.frame")
Axeman
  • 32,068
  • 8
  • 81
  • 94
NSS
  • 11
  • 3
  • consider revising your question by providing a reproducible example. See [here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) on how to create one. – mnm Jun 08 '18 at 12:35
  • `+ scale_color_identity()`. You are trying to use `ggplot` like base plotting, you usually want `ggplot` to create colors for you. If you give a better reproducible example (e.g. with the `diamonds` dataset), you may get more help. – Axeman Jun 08 '18 at 13:19
  • if your data is discrete and you want a nice color bar, have a look at this thread https://stackoverflow.com/questions/50506832/create-discrete-color-bar-with-varying-interval-widths-and-no-spacing-between-le/50540633?noredirect=1#comment88244484_50540633 – tjebo Jun 08 '18 at 15:43

0 Answers0