【发布时间】:2014-03-06 21:38:28
【问题描述】:
我正在尝试为 R 中 GGally 库中的 ggpairs 的散点图使用另一种调色板。请参阅 similar question here。
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