Scattermatrix in ggplot2 / GGally without density charts

I made a diffused matrix with the ggplot2 GGally extension with the following code

ggscatmat(dat2, columns = 2:6, color="car", alpha=0.8) + ggtitle("Korrelation") + theme(axis.text.x = element_text(angle=-40, vjust=1, hjust=0, size=10)) 

Now my problem is that in this case I really do not need a density layer or correlation coefficient. I only need scatterplots in the matrix. Is there a way to β€œremove” other faces? I can not find anything in the documentation.

I apologize for my bad English and thanks for any advice or help!

Scattermatrix with ggscatmat {GGally}

Edit: I found a not perfect solution with ggpairs yet:

 ggpairs(dat2, columns = 2:6, mapping= aes(color=car), upper = "blank",diag = "blank") + theme(axis.text.x = element_text(angle=-40, vjust=1, hjust=0, size=10)) 

But now there is no legend, and two plot-like labels have not yet been loaded: enter image description here

+5
source share
2 answers

You can manually delete parts of the plot by logging in with gtable

  removePanels <- function(plot) { g <- ggplotGrob(plot) # get panels to remove: upper + diagonal ids <- grep("panel", g$layout$name) cols <- sqrt(diff(range(ids)) +1) remove <- matrix(ids, ncol=cols) remove <- remove[upper.tri(remove, diag=TRUE)] # remove certain axis yax <- grep("axis-l", g$layout$name)[1] # first xax <- tail(grep("axis-b", g$layout$name), 1) #last # remove cetain strips ystrip <- grep("strip-right", g$layout$name)[1] xstrip <- tail(grep("strip-top", g$layout$name), 1) # remove grobs g$grobs[c(remove, xax, yax, ystrip, xstrip)] <- NULL g$layout <- g$layout[-c(remove, xax, yax, ystrip, xstrip),] g } # draw library(GGally) library(ggplot2) library(grid) p <- ggscatmat(iris, columns = 1:4, color="Species", alpha=0.8) + theme(axis.text.x = element_text(angle=-40, vjust=1, hjust=0, size=10)) grid.newpage() grid.draw(removePanels(p)) 
+4
source

Following the official documentation, you can set the ggpairs element to empty. In your case, you will be interested in changing the diag value to diag = "blank" , as shown in the example below.

Example

Using the mtcars data example, you can do the following:

 data("mtcars") require(GGally) ggpairs(data = mtcars[3:5], diag = "blank") 

results

The code will create the desired graph without a diagonal graph: Without diagonal

+3
source

Source: https://habr.com/ru/post/1247513/