Michael Friendly
2013-Mar-08 16:36 UTC
[R] ggplot2: modifying line width and background fill color for stat_smooth()
In the example below, from http://www.ling.upenn.edu/~joseff/rstudy/summer2010_ggplot2_intro.html I'd like to make (a) the fitted line thicker and (b) change the background fill color for the confidence envelope around each fitted line to a low-alpha transparent version of the same color used for the separate fitted lines for GENDER, rather than grey for both. How can I do this? donner<-read.csv("http://www.ling.upenn.edu/~joseff/data/donner.csv") ggplot(donner, aes(AGE, NFATE, color = GENDER))+ geom_point(position = position_jitter(height = 0.02, width = 0)) + stat_smooth(method = "glm", family = binomial, formula = y ~ poly(x,2)) For the line width, I tried, ggplot(donner, aes(AGE, NFATE, color = GENDER))+ geom_point(position = position_jitter(height = 0.02, width = 0)) + stat_smooth(aes(size=2), method = "glm", family = binomial, formula = y ~ poly(x,2)) This worked, but gave a spurious component labeled "2" in the plot legend. TIA, -Michael -- Michael Friendly Email: friendly AT yorku DOT ca Professor, Psychology Dept. & Chair, Quantitative Methods York University Voice: 416 736-2100 x66249 Fax: 416 736-5814 4700 Keele Street Web: http://www.datavis.ca Toronto, ONT M3J 1P3 CANADA [[alternative HTML version deleted]]
John Kane
2013-Mar-08 17:09 UTC
[R] ggplot2: modifying line width and background fill color for stat_smooth()
Is this roughly what you want? Shamelessly stolen , I mean , adapted from http://docs.ggplot2.org/0.9.3/stat_smooth.html donner<-read.csv("http://www.ling.upenn.edu/~joseff/data/donner.csv") ggplot(donner, aes(AGE, NFATE, colour = GENDER))+ geom_point(position = position_jitter(height = 0.02, width = 0)) + stat_smooth(method = "glm", family = binomial, formula = y ~ poly(x,2), alpha = 0.1, size=2, aes(fill = GENDER)) John Kane Kingston ON Canada> -----Original Message----- > From: friendly at yorku.ca > Sent: Fri, 08 Mar 2013 11:36:36 -0500 > To: r-help at r-project.org > Subject: [R] ggplot2: modifying line width and background fill color for > stat_smooth() > > In the example below, from > http://www.ling.upenn.edu/~joseff/rstudy/summer2010_ggplot2_intro.html > > I'd like to make (a) the fitted line thicker and (b) change the > background fill color for the confidence > envelope around each fitted line to a low-alpha transparent version of > the same color used > for the separate fitted lines for GENDER, rather than grey for both. > How can I do this? > > donner<-read.csv("http://www.ling.upenn.edu/~joseff/data/donner.csv") > > ggplot(donner, aes(AGE, NFATE, color = GENDER))+ > geom_point(position = position_jitter(height = 0.02, width = 0)) + > stat_smooth(method = "glm", family = binomial, formula = y ~ > poly(x,2)) > > For the line width, I tried, > > ggplot(donner, aes(AGE, NFATE, color = GENDER))+ > geom_point(position = position_jitter(height = 0.02, width = 0)) + > stat_smooth(aes(size=2), method = "glm", family = binomial, formula > y ~ poly(x,2)) > > This worked, but gave a spurious component labeled "2" in the plot > legend. > > TIA, > -Michael > > -- > Michael Friendly Email: friendly AT yorku DOT ca > Professor, Psychology Dept. & Chair, Quantitative Methods > York University Voice: 416 736-2100 x66249 Fax: 416 736-5814 > 4700 Keele Street Web: http://www.datavis.ca > Toronto, ONT M3J 1P3 CANADA > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.____________________________________________________________ FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your desktop!
Michael Friendly
2013-Mar-08 17:47 UTC
[R] ggplot2: modifying line width and background fill color for stat_smooth()
On 3/8/2013 12:09 PM, John Kane wrote:> donner<-read.csv("http://www.ling.upenn.edu/~joseff/data/donner.csv") > > ggplot(donner, aes(AGE, NFATE, colour = GENDER))+ > geom_point(position = position_jitter(height = 0.02, width = 0)) + > stat_smooth(method = "glm", family = binomial, formula = y ~ poly(x,2), > alpha = 0.1, size=2, aes(fill = GENDER))Yes, perfect -- exactly what I want! -- Michael Friendly Email: friendly AT yorku DOT ca Professor, Psychology Dept. & Chair, Quantitative Methods York University Voice: 416 736-2100 x66249 Fax: 416 736-5814 4700 Keele Street Web: http://www.datavis.ca Toronto, ONT M3J 1P3 CANADA
Maybe Matching Threads
- ggplot2: stat_smooth for family=binomial with cbind(Y, N) formula
- plot 3 lines with ggplot2
- ggplot geom_boxplot and stat_smooth
- Ggplot2: Moving legend, change fill and removal of space between plots when using grid.arrange() possible use of facet_grid?
- ggplot: problem with fill option in stat_smooth()