什么是ggplot2中平滑曲线的默认颜色?

时间:2016-01-11 14:57:49

标签: r ggplot2

我想用两种颜色制作报告。我想知道ggplot2中的平滑曲线的默认颜色是什么,所以我可以相应地命名我的bar / line / pie。谢谢。

1 个答案:

答案 0 :(得分:5)

关注@ Konrad的评论指向here

library("ggplot2")
dd <- data.frame(x=1:10,y=1:10)
g1 <- ggplot(dd,aes(x,y))+geom_smooth()
unique(ggplot_build(g1)$data[[1]]$colour)  ## "#3366FF"
plot(1,1,cex=8,pch=16,col="#3366FF")

enter image description here

这实际上并不是emulate ggplot colour palette的完全重复:如果我们建立一个三类彩色情节加上光滑的我们得到:

sapply(ggplot_build(g1)$data,function(x) unique(x$colour))
## [[1]]
## [1] "#F8766D" "#00BA38" "#619CFF" # three colours from colour wheel 
## [[2]]
## [1] "#3366FF"    # geom_smooth colour
相关问题