【问题标题】:Kernel density scatter plot in RR中的核密度散点图
【发布时间】:2015-09-12 05:40:11
【问题描述】:

我看到了beautiful plot,我想重新创建它。这是一个示例,展示了我到目前为止所获得的内容:

# kernel density scatterplot
library(RColorBrewer)
library(MASS)
greyscale <- rev(brewer.pal(4, "Greys"))
x <- rnorm(20000, mean=5, sd=4.5); x <- x[x>0]
y <- x + rnorm(length(x), mean=.2, sd=.4)
z <- kde2d(x, y, n=100)
plot(x, y, pch=".", col="hotpink")
contour(z, drawlabels=FALSE, nlevels=4, col=greyscale, add=T)
abline(c(0,1), lty=1, lwd=2)
abline(lm(y~x), lty=2, lwd=2)

我正在努力用颜色填充轮廓。这是smoothScatter 或其他软件包的工作吗?我怀疑这可能是因为我使用了kde2d,如果是这样,有人可以解释一下这个功能或将我链接到一个好的教程吗?

非常感谢!

附:最终的图像应该是灰度的

【问题讨论】:

    标签: r scatter-plot kernel-density density-plot


    【解决方案1】:

    似乎你想要一个填充的轮廓而不是一个轮廓。也许

    library(RColorBrewer)
    library(MASS)
    greyscale <-brewer.pal(5, "Greys")
    x <- rnorm(20000, mean=5, sd=4.5); x <- x[x>0]
    y <- x + rnorm(length(x), mean=.2, sd=.4)
    z <- kde2d(x, y, n=100)
    
    filled.contour(z, nlevels=4, col=greyscale, plot.axes = {
        axis(1); axis(2)
        #points(x, y, pch=".", col="hotpink")   
        abline(c(0,1), lty=1, lwd=2)
        abline(lm(y~x), lty=2, lwd=2)
    })
    

    给了

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-01-07
      • 2020-07-28
      • 2018-01-23
      • 2020-10-29
      • 2014-01-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多