这与R和ggpairs中用户定义的调色板中的问题相同 ,或者有没有办法使用ggplot更改GGally :: ggpairs的调色板?
只有那里的解决方案不再有效.
我也想更改调色板,但有没有办法使用ggplot更改GGally :: ggpairs的调色板?不再起作用了.该怎么办?
MWE:
library(GGally) library(ggplot2) data(diamonds, package="ggplot2") diamonds.samp <- diamonds[sample(1:dim(diamonds)[1],200),] ggpairs( diamonds.samp[,1:2], 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" )
我想补充一下
scale_colour_manual(values=c('red','blue','green','red','blue'))
(显然这只是虚拟代码)并得到类似的东西(我没有绘制所有的点):
一种解决方案是从ggmatrix
添加新图中提取每个图scale_
,然后将其重新分配回矩阵.
例
library(GGally) library(ggplot2) data(diamonds, package="ggplot2") diamonds.samp <- diamonds[sample(1:dim(diamonds)[1],200),] p <- ggpairs( diamonds.samp[,1:2], 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" )
循环通过每个图改变相关的尺度
for(i in 1:p$nrow) { for(j in 1:p$ncol){ p[i,j] <- p[i,j] + scale_fill_manual(values=c("red", "blue", "green", "yellow", "black")) + scale_color_manual(values=c("red", "blue", "green", "yellow", "black")) } } p
给