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

标签 r ggplot2

我想只使用两种颜色来制作我的报告。我想知道 ggplot2 中平滑曲线的默认颜色是什么,以便我可以相应地命名我的条形/线条/饼图。谢谢。

最佳答案

按照@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

关于r - ggplot2中平滑曲线的默认颜色是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34724501/

相关文章:

r - 在 for 循环中将数据帧附加在一起

r - "Error in ... %*% ... : non-conformable arguments"在回归中使用自己的函数

r - 使用 ggplot2 将不同的图像插入到单个面板中

r - 绘图时将线延伸到末端?

r - 将数据添加到现有的 ggplot2 图中

r - 带有 magrittr tee 运算符的多个 ggplots

r - 我如何在 intellij idea 中运行(配置为运行).r 文件?

r - 如何从多个向量创建数据框?

r - 使用对数刻度时,如何在 ggplot2 中设置轴范围?

r - 如何根据R中缺失数据的日期列计算数据框中多列的月平均值