ggplot2/GGally 中的散点矩阵,没有密度图

Scattermatrix in ggplot2/GGally without density plots

我使用以下代码用 ggplot2 扩展 GGally 制作了一个散点矩阵

  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))

现在我的问题是,在这种情况下,我真的不需要密度线图或相关系数。我只需要矩阵中的散点图。有没有办法 "delete" 其他方面?我无法#T 在文档中找到任何内容。

请原谅我的英语不好,感谢您的任何建议或帮助!

编辑:我用 ggpairs 找到了一个还不完美的解决方案:

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))

但现在没有图例了,两个看起来像情节的标签还没有完全加载:

official documentation, you can set an element of the ggpairs 之后变为 空白。 在您的情况下,您可能有兴趣将 diag 的值更改为diag = "blank" ,如下例所示。

例子

mtcars 数据为例,您可以执行以下操作:

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

结果

代码将生成没有对角线图的所需图表:

您可以通过摆弄 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))