Take the following example data:
x <- rnorm(10000)
y <- rnorm(10000) * x
z <- rnorm(10000) * y
df <- data.frame(x,y,z)
We can produce a scatter plot matrix as follows:
splom(df)
But due to the large number of overlapping points it is hard to gauge the density.
Is there a straightforwards way to replace each plot with a bivariate histogram heatmap, like those produced by squash?
library(squash)
hist2(df$x, df$y)
The panel.hexbinplot
is convenient for large datasets.
library(hexbin)
splom(df, panel=panel.hexbinplot)
You can customize the panel function like this :
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)
You can play with teh style
parameter.
here's another option that's more in-line with your original request
# 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" )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With