Groups
Sign in
Groups
ggplot2
Conversations
About
Send feedback
Help
shading between two lines
23 views
Skip to first unread message
Michael Cawthon
unread,
Feb 13, 2015, 10:13:50 PM
2/13/15
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ggplot2
Given a data frame:
data <- data.frame(year = 2001:2010, y1 = 1:10, y2 = seq(10,13,1/3))
We plot the two lines over time:
ggplot(data, aes(x = year)) + geom_line(aes(y=y1), color = 'red') + geom_line(aes(y = y2), color = 'blue')
Suppose we want to shade a region in between the two lines; how can this be accomplished?
I've attempted using both geom_area() and geom_polygon(), but I am struggling with the appropriate mapping.
Thank you for your help.
Ista Zahn
unread,
Feb 13, 2015, 10:26:14 PM
2/13/15
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Michael Cawthon, ggplot2
I think you want geom_ribbon:
ggplot(data, aes(x = year)) +
geom_ribbon(aes(ymin = y1, ymax = y2), fill = "green") +
geom_line(aes(y=y1), color = 'red') +
geom_line(aes(y = y2), color = 'blue')
Best,
Ista
> --
> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example:
>
https://github.com/hadley/devtools/wiki/Reproducibility
>
> To post: email
ggp...@googlegroups.com
> To unsubscribe: email
ggplot2+u...@googlegroups.com
> More options:
http://groups.google.com/group/ggplot2
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ggplot2" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to
ggplot2+u...@googlegroups.com
.
> For more options, visit
https://groups.google.com/d/optout
.
Reply all
Reply to author
Forward
0 new messages