2016-01-11 51 views
7

隨着在GGally :: ggpairs中編輯單個ggplots:我如何讓密度圖未在ggpairs中填充?

library(GGally) 

data(diamonds, package="ggplot2") 
diamonds.samp <- diamonds[sample(1:dim(diamonds)[1],200),] 

# Custom Example 
ggpairs(
diamonds.samp[,1:5], 
mapping = ggplot2::aes(color = cut), 
upper = list(continuous = wrap("density", alpha = 0.5), combo = "box"), 
lower = list(continuous = wrap("points", alpha = 0.3), combo = wrap("dot", alpha = 0.4)), 
diag = list(continuous = wrap("densityDiag")), 
title = "Diamonds" 
) 

我得到

enter image description here

如何使對角線密度圖不被填補,只列出了?

種類的作品...但不是真的。

這真的很醜 - 就代碼而言 - 因爲它對我沒有任何意義。另外,它在這裏不起作用,因爲它也改變了直方圖。

ggpairs(
    diamonds.samp[,1:5], 
    mapping = ggplot2::aes(color = cut), 
    upper = list(continuous = wrap("density", alpha = 0.5), combo = "box"), 
    lower = list(continuous = wrap("points", alpha = 0.3), combo = wrap("dot", alpha = 0.4)), 
    diag = list(continuous = wrap("densityDiag"), mapping = ggplot2::aes(fill=carat)), 
    title = "Diamonds" 
) 

enter image description here

+0

發現也看到https://github.com/bbolker/stat744/ blob/master/lectures/explore_multiway.R#L109 –

回答

9

的問題的答案可以在https://cran.r-project.org/web/packages/GGally/vignettes/ggpairs.htmlarchived here

ggally_mysmooth <- function(data, mapping, ...){ 
    ggplot(data = data, mapping=mapping) + 
    geom_density(mapping = aes_string(color="cut"), fill=NA) 
} 
ggpairs(
    diamonds.samp[,1:5], 
    mapping = aes(color = cut), 
    upper = list(continuous = wrap("density", alpha = 0.5), combo = "box"), 
    lower = list(continuous = wrap("points", alpha = 0.3), combo = wrap("dot", alpha = 0.4)), 
    diag = list(continuous = ggally_mysmooth), 
    title = "Diamonds" 
) 

enter image description here

+1

鏈接的頁面不見了,幸運的是Wayback Machine有它https://web.archive .ORG /網絡/ 20160320034441/cran.r-project.org /網絡/包/ GGally /插圖/ ggpairs.html – JimLohse

相關問題