R legend for color density scatterplot produced using smoothScatter

后端 未结 1 731
醉酒成梦
醉酒成梦 2020-12-30 13:15

I am producing a color density scatterplot in R using the smoothScatter() function.

Example:

## A largish data set
n <- 10000
x1  &         


        
相关标签:
1条回答
  • 2020-12-30 13:45

    Here is an answer that relies on fields::imageplot and some fiddling with par(mar) to get the margins correct

    fudgeit <- function(){
      xm <- get('xm', envir = parent.frame(1))
      ym <- get('ym', envir = parent.frame(1))
      z  <- get('dens', envir = parent.frame(1))
      colramp <- get('colramp', parent.frame(1))
      fields::image.plot(xm,ym,z, col = colramp(256), legend.only = T, add =F)
    }
    
    par(mar = c(5,4,4,5) + .1)
    smoothScatter(x, nrpoints = 0, postPlotHook = fudgeit)
    

    enter image description here

    You can fiddle around with image.plot to get what you want and look at ?bkde2D and the transformation argument to smoothScatter to get an idea of what the colours represent.

    0 讨论(0)
提交回复
热议问题