更新:
GGAlly再次更新,并在这个答案黑客也不工作了,但总算有一个非-hack解决方案:给
scales <- scale_colour_brewer(type = 'qual') %+% scale_fill_brewer(type = 'qual')
你可以做(在希望面向未来的方式)
for (row in seq_len(ps$nrow))
for (col in seq_len(ps$ncol))
ps[row, col] <- ps[row, col] + scales
老办法
在其他答案的黑客不工作了,所以让我们来破解一个新的!
一个ggpairs
对象的内部结构是数据集和字符串的列表:
> dta <- data.frame(a=1:6, b=7:12, c=c('f', 'g'))
> ps <- ggpairs(dta, 1:2, colour = 'c')
> str(ps)
List of 10
$ data :'data.frame': 2 obs. of 3 variables:
..$ a: int [1:2] 1 2
..$ b: int [1:2] 3 4
..$ c: int [1:2] 5 6
$ columns : int [1:3] 1 2 3
$ plots :List of 9
..$ : chr "ggally_densityDiag(ggally_data, ggplot2::aes(x = a, colour = c))"
..$ : chr "ggally_cor(ggally_data, ggplot2::aes(x = b, y = a, colour = c))"
[...]
$ gg : NULL
- attr(*, "class")= chr [1:2] "gg" "ggpairs"
> ps
为了修改的情节,在情节的对象的各个串需要进行修改以包含附加命令。为此,我们使用deparse(substitute(argument))
获得包含用户通过代码的字符串,并将其追加到每一个情节电话:
add_to_plots <- function(pairs, modification) {
str <- deparse(substitute(modification))
pairs$plots <- lapply(pairs$plots, function(s) paste(s, '+', str))
pairs
}
> add_to_plots(ps, scale_colour_brewer(type = 'qual'))
不错的黑客!希望这可以保持良好的可靠性。 –