Re: [R] ggplot2 & ribbon

From: hadley wickham <h.wickham_at_gmail.com>
Date: Sat, 16 Feb 2008 09:37:44 -0600

> p<-ggplot(reading.melt,aes(x=Date,y=value))
> p+geom_path(aes(colour=Type),size=2)+facet_grid(variable~.)
>
> but can't figure out
> (1) How to add a transparent shade between the Paid & Total lines. I've
> tried the ribbon function, but cant seem to get it to shade between the
> lines

To do this you'll need the data in a different format

df <- cast(reading.melt, ... ~ Type)

Then add on a ribbon as follows

p <- ggplot(reading.melt,aes(x=Date)) +
 facet_grid(variable ~ .) +
 geom_ribbon(aes(min = Paid, max=Total), data=df, fill=alpha("black", 0.1), colour=NA) +
 geom_path(aes(colour=Type ,y=value))

> (2) Add a left justified title to the chart

p + opts(title = "My title")

adds a title, and to left justify it, you need to use grid to modify it:

grid.edit("title", x=unit(0, "npc"), hjust=0)

Hadley

-- 
http://had.co.nz/

______________________________________________
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.
Received on Sat 16 Feb 2008 - 15:42:20 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 16 Feb 2008 - 16:30:14 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive