Names in diagonal in ggpairs (R)

Viewed 317

I've been searching everywhere on how to replace the diagonal in this correlation plot matrix with the names of my variables...

Is there anyway to do so?

contVar <- c("survived", "age", "sibsp", "parch")
ggpairs(na.omit(titanic)[, contVar], diag = list("continuous" = "blankDiag"))

Correlation matrix plot

enter image description here

And is it possible to make it with plotly?

Btw, this is what my data looks like

> head(titanic)
  pclass survived    sex   age sibsp parch
1      1        1 female 29.00     0     0
2      1        1   male  0.92     1     2
3      1        0 female  2.00     1     2
4      1        0   male 30.00     1     2
5      1        0 female 25.00     1     2
6      1        1   male 48.00     0     0

Update The code below is now satisfactory. But the plotly-conversion looks weird. How come?

ggpairs(na.omit(titanic)[, contVar], upper = list(continuous = "cor"), lower = list(continuous = wrap("points", alpha = 0.3)),
    diag = list("continuous" = function(data, mapping, ...){ggally_text(rlang::as_label(mapping$x),col="black", size=8)+theme_void()})
    )+theme(strip.background = element_rect(fill = "white"), strip.text =  element_blank())

ggplotly-plot

0 Answers
Related