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

标签 r ggplot2 ggally

我使用以下代码使用 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))

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

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

Scattermatrix with ggscatmat {GGally}

编辑:我发现 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))

但现在不再有图例了,两个标签看起来好像情节还没有完全加载:enter image description here

最佳答案

您可以通过修改 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))

关于r - ggplot2/GGally 中的散点矩阵,没有密度图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36741664/

相关文章:

删除 ggpairs 中的密度轴文本

r - 如何在 ggpairs (R) 中显示带有 scale_colour_manual 的彩色组相关性?

r - ggplot2:如何绘制包含特殊字符的列?

r - 在R中绘制椭圆/双曲线

r - 删除数据帧中的最后一个值,将该行绑定(bind)到同一数据帧,并在第一列中设置零,重复 100 次

r - R中的autoplot函数和plot函数有什么区别

r - 是否可以将图例放置在R中ggplot的右上方?

r - 各组最近值的总和

r - 在我的分组计数中使用 R 中的 data.table 重复行