【问题标题】:High density plots (hexbin) within correlogram plots (pairs)相关图(对)内的高密度图(hexbin)
【发布时间】:2014-07-26 12:30:48
【问题描述】:

我想使用 R 函数 pair() 构建相关图。在下面的面板中,我想表示使用 hexbin() 生成的高密度图。但是,我无法将 hexbin 图定位在下面板的正确位置。

这是生成每个十六进制图的函数:

density_pts<- function(x,y,...){
  bin <- hexbin(x, y, xbins=50)
  plot(bin, main="", xlab="", ylab="",legend=F,newpage = FALSE)
}

问题是 density_pts 生成的每个图都不适合下部面板框。我应该使用哪些参数来正确定位它们?

这里和问题的例子:

data<-data.frame(A = sample(1:1000),B = sample(1:1000),C = sample(1:1000),D = sample(1:1000))

density_pts<- function(x,y,...){
  bin <- hexbin(x, y, xbins=50)
  plot(bin, main="", xlab="", ylab="",legend=F)
}

# default scatterplot
pairs(data,upper.panel = NULL)

# custom high density plot ::: problem :::
pairs(data,lower.panel=density_pts,upper.panel = NULL)

非常感谢!

【问题讨论】:

  • 感谢您的建议,我编辑了主帖。
  • hexbin对象的plot方法通过S4系统调度,生成网格绘图对象。 pair 函数是一个基本的图形函数,所以遇到问题也就不足为奇了。

标签: r plot


【解决方案1】:

你可以只使用hexplom()函数,这是splom()hexbin版本:

density_pts<- function(x,y,...){
  bin <- hexbin(x, y, xbins=50)
  plot(bin, main="", xlab="", ylab="",legend=F,newpage = FALSE)
}
data<-data.frame(A = sample(1:1000),B = sample(1:1000),C = sample(1:1000),D = sample(1:1000))

density_pts<- function(x,y,...){
  bin <- hexbin(x, y, xbins=50)
  plot(bin, main="", xlab="", ylab="",legend=F)
}

# default scatterplot
pairs(data,upper.panel = NULL)

# custom high density plot ::: problem solved :::
hexplom(data, upper.panel = NULL)

导致:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-01-20
    • 1970-01-01
    • 1970-01-01
    • 2013-11-19
    • 1970-01-01
    • 2019-09-28
    • 2012-07-23
    • 2017-11-01
    相关资源
    最近更新 更多