以以下示例数据为例:
x <- rnorm(10000)
y <- rnorm(10000) * x
z <- rnorm(10000) * y
df <- data.frame(x,y,z)
我们可以生成一个散点图矩阵,如下所示:
splom(df)
但由于大量重叠点,很难衡量密度。
有没有一种简单的方法可以用二元直方图热图替换每个图,就像squash产生的那样?
library(squash)
hist2(df$x, df$y)
这panel.hexbinplot
对于大型数据集很方便。
library(hexbin)
splom(df, panel=panel.hexbinplot)
您可以像这样自定义面板功能:
library(hexbin)
splom(df,
panel = function(x, y, ...){
panel.hexbinplot(x, y, style = "nested.lattice",
type = c("g", "smooth"),col='blue', ...)
},
pscale=0, varname.cex=0.7)
您可以使用 tehstyle
参数。
这是另一个更符合您的原始要求的选项
# run the code you've provided
library(lattice)
x <- rnorm(10000)
y <- rnorm(10000) * x
z <- rnorm(10000) * y
df <- data.frame(x,y,z)
# look at each of these options one-by-one.. go slowly!
# here's your original
splom(df)
# here each point has been set to very transparent
splom(df , col="#00000005" )
# here each point has been set to moderately transparent
splom(df , col="#00000025" )
# here each point has been set to less transparent
splom(df , col="#00000050" )
这不是您要求的方法,但确实可以帮助您解决您描述的基本问题:)
# run the code you've provided
library(lattice)
x <- rnorm(10000)
y <- rnorm(10000) * x
z <- rnorm(10000) * y
df <- data.frame(x,y,z)
# figure out what ten percent of the total records are
ten.percent <- nrow( df ) / 10
# create a new data frame `df2` containing
# a randomly-sampled ten percent of the original data frame
df2 <- df[ sample( nrow( df ) , ten.percent ) , ]
# now `splom` that.. and notice it's easier to see densities
splom(df2)