2

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

mas2
  • 75
  • 11
  • 1
    `ggpairs(yourdata, diag = list("continuous" = function(data, mapping, ...) { ggally_text(rlang::as_label(mapping$x),col="blue", size=10) + theme_void() }))` ... tweak to how you want it to look – user20650 Mar 08 '21 at 01:11
  • @user20650 I'm not quite sure how to build the function :-/ – mas2 Mar 08 '21 at 14:43
  • how do you mean please? if you substitute `na.omit(titanic)[, contVar]` for `yourdata` it should just work – user20650 Mar 08 '21 at 14:48
  • Oh, lol. Thanks - that did work. Now how do I get rid of the "names" around my plot such that they only appear in the diag? :) – mas2 Mar 08 '21 at 14:52
  • From `?ggpairs` i'd of thought `showStrips` would manage this but as far as I can see it doesn't seem to do anything. Adding `theme( strip.background = element_rect(fill = "white"), strip.text = element_blank() )` removes it but leaves a bit of space where the strips were – user20650 Mar 08 '21 at 15:07
  • 1
    ps there is also `ggpairs(mtcars[1:3], axisLabels = "internal")` which may suit – user20650 Mar 08 '21 at 15:13
  • @user20650 Adding the theme was the way to go. I already tried the axisLabels = "internal" but then the axis values is inside the diagonal. If I convert this plot to plotly with `ggplotly()` it looks like trash. Am I doing anything wrong? (Look at the picture I added in the question) – mas2 Mar 08 '21 at 15:22
  • ... sorry I don't use ggplotly. It might be worth asking a new question specifically on this -- you will likely get more views on a new question rather than an edit. If you do it would be good to add all packages to your question and explain what *"looks like trash"* means – user20650 Mar 08 '21 at 15:25

0 Answers0