2016-01-11 15 views
7

VớiChỉnh sửa ggplots cá nhân trong GGally :: ggpairs: Làm thế nào để tôi có cốt truyện mật độ không được lấp đầy trong 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" 
) 

tôi nhận được

enter image description here

Làm thế nào để làm cho âm mưu mật độ đường chéo không được lấp đầy, và chỉ hiển thị các dòng?

Loại tác phẩm ... nhưng không thực sự.

Điều này thực sự xấu - về mặt mã - vì nó không có ý nghĩa thực sự đối với tôi. Ngoài ra, nó không hoạt động ở đây, bởi vì nó cũng thay đổi biểu đồ.

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

cũng thấy https://github.com/bbolker/stat744/ blob/master/lectures/explore_multiway.R # L109 –

Trả lời

9

Câu trả lời cho câu hỏi có thể được tìm thấy trên https://cran.r-project.org/web/packages/GGally/vignettes/ggpairs.html (archived 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

Trang liên kết đó đã biến mất, may mắn là Máy Wayback có https: //web.archive .org/web/20160320034441/cran.r-project.org/web/packages/GGally/vignettes/ggpairs.html – JimLohse

Các vấn đề liên quan