[R] adding custom details to ggplot subplots

hadley wickham h.wickham at gmail.com
Mon May 14 12:56:11 CEST 2007


Hi Antonio,

Again, you can't do it in the current version, but it's pretty easy to
do in the new version.  The following example comes from the
documentation:

# Slopes and intercepts as data
p <- ggplot(mtcars, aes(x = wt, y=mpg), . ~ cyl) + geom_point()
df <- data.frame(intercept=25, slope=2)
p + geom_abline(data=df)

# Slopes and intercepts from linear model
coefs <- do.call(rbind, by(mtcars, mtcars$cyl, function(df) {
	m <- lm(mpg ~ wt, data=df)
	data.frame(cyl = df$cyl[1], intercept=coef(m)[1], slope=coef(m)[2])
}))
str(coefs)
p + geom_abline(data=coefs)

Hadley


On 5/13/07, Antonio, Fabio Di Narzo <antonio.fabio at gmail.com> wrote:
> Hi all.
> Consider the following example from ggplot vignette:
>
> ggpoint( ggplot(tips, .~sex, ae=list(y=tip, x=total_bill)) )
>
> You have one scatterplot per sex. With 'ggabline' I can add one or more
> lines to each subplot at the same time.
> How can I add different lines in each subplot?
> Note that I have 0<knowledge<little of grid graphics.
>
> Antonio.
> --
> Antonio, Fabio Di Narzo
> Ph.D. student at
> Department of Statistical Sciences
> University of Bologna, Italy
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>



More information about the R-help mailing list