更新:
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'))
不錯的黑客!希望這可以保持良好的可靠性。 –