仅点的 ggpairs 格式

ggpairs formatting for points only

我希望增加点的大小并用黑色勾勒出它们的轮廓,同时在其余图中保持相同的线宽。

library(ggplot2)
library(GGally)

pp <- ggpairs(pp.sed, columns = c(1,2), aes(color=pond.id, alpha = 0.5)) +
  theme_bw()
print(pp)

这给了我下图: 再现性和 TIA 数据!

> dput(pp.sed)
structure(list(Fe.259.941 = c(905.2628883, 825.7883359, 6846.128702, 
1032.932924, 997.8037721, 588.9599882, 6107.641947, 798.4493611, 
1046.38376, 685.2485692, 6452.273486, 730.8656684, 902.8585447, 
1039.886406, 7408.801001, 2512.089991, 911.2101809, 941.3712067, 
659.1069185, 1070.090445, 1017.666402, 925.3221586, 645.0500668, 
954.0009756, 1022.594904, 803.5865352, 7653.184537, 1082.714082, 
1048.51115, 773.9070604, 6889.060748, 973.0971769, 1002.091143, 
798.9670583, 5089.035978, 2361.713222, 970.8258109, 748.3574529, 
3942.04816, 889.1760124), Mn.257.611 = c(17.24667962, 14.90488024, 
14.39265671, 20.51133433, 19.92596564, 11.76690074, 19.76386229, 
14.29779164, 20.23646264, 13.55374658, 16.8847698, 13.11784439, 
15.91777975, 20.64068844, 16.78681661, 28.61732162, 15.88328987, 
19.59750367, 13.09735943, 21.59458118, 17.680152, 19.87127449, 
12.8082581, 20.12050221, 17.57143193, 18.72196029, 16.21525793, 
22.0518966, 18.39642397, 18.32238508, 16.17696923, 20.69668404, 
17.96018218, 18.71945309, 16.50162126, 30.60719123, 17.69058768, 
14.99048753, 16.28302375, 18.32277507), pond.id = structure(c(6L, 
5L, 2L, 1L, 3L, 5L, 2L, 1L, 3L, 5L, 2L, 1L, 6L, 3L, 2L, 4L, 6L, 
3L, 4L, 4L, 6L, 3L, 4L, 1L, 6L, 3L, 2L, 1L, 6L, 3L, 2L, 1L, 6L, 
3L, 2L, 1L, 6L, 5L, 2L, 1L), .Label = c("LIL", "RHM", "SCS", 
"STN", "STS", "TS"), class = "factor")), class = "data.frame", row.names = c(11L, 
12L, 13L, 15L, 26L, 27L, 28L, 30L, 36L, 37L, 38L, 40L, 101L, 
102L, 103L, 105L, 127L, 128L, 129L, 131L, 142L, 143L, 144L, 146L, 
157L, 158L, 159L, 161L, 172L, 173L, 174L, 176L, 184L, 185L, 186L, 
188L, 199L, 200L, 201L, 203L))

GGally 包已经提供了一系列 wrap_xxx 函数,可用于设置参数以覆盖默认行为,例如使用 wrap 您可以使用 wrap(ggally_points, size = 5).

覆盖默认的 size

要使用包装函数而不是默认函数,您必须调用

ggpairs(..., lower = list(continuous = wrap(ggally_points, size = 5))).

切换大纲有点棘手。使用 wrap 我们可以将点的 shape 切换为 21 并将轮廓 color 设置为“黑色”。但是,这样做时点不再有颜色。不幸的是,我没有找到覆盖映射的方法。虽然可以添加全局填充 aes,但这样做的缺点是我们会丢失密度的黑色轮廓。

解决这个问题的一个方法是为 ggally_points 编写一个包装器,它调整 mapping 以便使用 fill aes 而不是 color

library(ggplot2)
library(GGally)

ggally_points_filled <- function(data, mapping, ...) {
  names(mapping)[grepl("^colour", names(mapping))] <- "fill"
  ggally_points(data, mapping, ..., shape = 21)
}
w_ggally_points_filled <- wrap(ggally_points_filled, size = 5, color = "black")

ggpairs(pp.sed, columns = c(1, 2), aes(color = pond.id, alpha = 0.5),
        lower = list(continuous = w_ggally_points_filled)) +
  theme_bw()