1

I am working with the R programming language. I simulated some data and made the following plot:

a = rnorm(1000,10,10)
b = rnorm(1000,10,10)
c = rnorm(1000,10, 1)

d = data.frame(a,b,c)

plot(x = d$a, y = d$b, col = d$c)

enter image description here

In the above plot, the points are colored according to the value of "c". Is it possible to add a legend that shows which colors are associated with which values of "c"?

I know how how to do this using the plotly library:

library(plotly)
 plot_ly(data = d, type = "scatter", mode = "markers", x = ~a, y = ~ b, color = ~ c)

But is it possible to make this "color gradient legend" using base R?

Thanks

enter image description here

stats_noob
  • 5,401
  • 4
  • 27
  • 83
  • Note: this color scale is automatically added when I use the ggplot2 library: ggplot(d, aes(x=a, y=b, color=c)) + geom_point() – stats_noob Mar 03 '21 at 03:50
  • Potential duplicate: https://stackoverflow.com/a/13355440/6851825 or https://stackoverflow.com/a/24221547/6851825 – Jon Spring Mar 03 '21 at 05:16

0 Answers0