我想在R中的GGally
库中使用ggpairs
的散点图的另一个调色板。请参阅similar question here。R和ggpairs中的用户自定义调色板
library(ggplot2)
library(GGally)
作品
ggplot(iris, aes(x=Sepal.Width, colour=Species)) + stat_ecdf() + scale_color_brewer(palette="Spectral")
同样适用
ggplot <- function(...) ggplot2::ggplot(...) + scale_color_brewer(palette="Spectral")
ggplot(iris, aes(x=Sepal.Width, colour=Species)) + stat_ecdf()
不工作
ggplot <- function(...) ggplot2::ggplot(...) + scale_color_brewer(palette="Spectral")
ggpairs(iris,
columns=, c("Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width"),
colour='Species',
lower=list(continuous='points'),
axisLabels='none',
upper=list(continuous='blank')
)
但加入
putPlot(p, ggplot(iris, aes(x=Sepal.Length, colour=Species)) + stat_ecdf(), 1,1)
增加在正确的颜色的曲线。
解决方法
我可以getPlot事后改变情节,但是这不是漂亮..
subplot <- getPlot(a, 2, 1) # retrieve the top left chart
subplotNew <- subplot + scale_color_brewer(palette="Spectral")
a <- putPlot(a, subplotNew, 2, 1)
如何更改配色方案的散点图中ggpairs?更具体地说,我想手动定义像这样的颜色
scale_colour_manual(values=c("#FF0000","#000000", "#0000FF","#00FF00"))
谢谢!
嗨,你可以将'ggpairs'阴谋存储在一个对象中,比如'gg'并修改'gg $ plots' –