How to enable density coloring in a pair correlation scattering diagram

I have the following code:

library(GGally)
library(nycflights13)
library(tidyverse)

dat <- nycflights13::flights %>% 
       select(dep_time, sched_dep_time, dep_delay,  arr_time, sched_arr_time, arr_delay)  %>% 
       sample_frac(0.01)
dat
ggpairs(dat)

He produces this:

enter image description here

How to add color density so that it looks like this:

enter image description here

+6
source share
1 answer

Using ideas from How to reproduce smoothScatter smoothing plugin in ggplot? , R - Smoothing colors and adding legend to scatterplot and How to use the loess method in GGally :: ggpairs using the bypass function , you can define your own function to go to ggpairs.

my_fn <- function(data, mapping, ...){
      p <- ggplot(data = data, mapping = mapping) + 
        stat_density2d(aes(fill=..density..), geom="tile", contour = FALSE) +
        scale_fill_gradientn(colours=rainbow(100))
      p
}

ggpairs(dat, lower=list(continuous=my_fn))

EDIT

: ":" ?

diag onal upper. , ( , geom_histogram), diag=list(continuous=wrap("barDiag", binwidth=100)) upper=list(continuous="blank"). *corr:*, - . cor_fun ggpairs , .

,

ggpairs(dat, lower=list(continuous=my_fn),
        diag=list(continuous=wrap("barDiag", binwidth=100)),
        upper=list(continuous=wrap(cor_fun, sz=10, stars=FALSE))
        )

enter image description here

: , OP?

, barDiag, fill colour. , diag

diag=list(continuous=wrap("barDiag", binwidth=100, fill="brown", col="black")) 

(fill , col )

+5

All Articles