I'd like to make my report using only two colors. I would like to know what's the default color of smooth curve in ggplot2 called so I can name my bar/line/pie accordingly. Thanks.
Asked
Active
Viewed 1,342 times
5
-
Option 1: use ggplot-default colours. Option 2: use your own set of colours everywhere, including ggplot – Heroka Jan 11 '16 at 16:02
-
Have a look at [this answer](http://stackoverflow.com/a/25211125/1655567) the `ggplot_build()` function can do precisely what you want. – Konrad Jan 11 '16 at 16:05
-
1The blue used in the geom_smooth line does not appear to be the same as those generated by the default color palette formula 'equally spaced hues around the color wheel, starting from 15'. @Ben Bolker's answer below is the only place I've found an answer to this specific and distinct question. – Omar Wasow Jul 19 '17 at 20:17
1 Answers
6
Following @Konrad's comment pointing 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")
This is not actually an exact duplicate of emulate ggplot colour palette: if we build a three-category coloured plot plus a smooth we get:
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

Community
- 1
- 1

Ben Bolker
- 211,554
- 25
- 370
- 453