簡體   English   中英

沒有密度圖的ggplot2 / GGally中的Scattermatrix

[英]Scattermatrix in ggplot2/GGally without density plots

我使用以下代碼使用ggplot2擴展GGally創建了一個scattermatrix

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

現在我的問題是,在這種情況下,我並不需要密度線圖或相關系數。我只想要矩陣中的散點圖。 有沒有辦法“刪除”其他方面? 我可以#T在文檔中找到任何內容。

請原諒我的英文不好,謝謝你的建議或幫助!

帶有ggscatmat的Scattermatrix {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))

但是現在已經沒有傳說了,看起來像情節的兩個標簽還沒有完全加載: 在此輸入圖像描述

你可以通過搞亂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))

官方文檔之后 ,您可以將ggpairs的元素設置為空白。 在您的情況下,您將有興趣將diag的值更改為diag = "blank" ,如下例所示。

mtcars數據的示例中,您可以執行以下操作:

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

結果

代碼將生成沒有對角線圖的所需圖表: 沒有對角線

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM