[英]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在文檔中找到任何內容。
請原諒我的英文不好,謝謝你的建議或幫助!
編輯:我發現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))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.