Hi:
Try
ggplot() +
geom_rect(data = presidential, aes(ymin = 2500, ymax = 12000, xmin
= start, xmax = end, fill = party)) +
geom_line(data = economics, aes(x = date, y = unemploy)) +
coord_cartesian(y = c(2500, 12000)) +
scale_x_date(expand = c(0, 0))
Pass the data frames to the individual geoms and make the aesthetic
mappings local to the geom. The last two lines exist to crop the
graphics region to the extent of the x/y ranges.
You might benefit by *setting* the alpha transparency of the
geom_rect() layer to something in the vicinity of 0.3 if you want to
see the grid line guides - moreover, ymin and ymax are also set, so a
more 'correct' way of specifying the plot with a smaller alpha might
be
ggplot() +
geom_rect(data = presidential, aes(xmin = start, xmax = end, fill = party),
ymin = 2500, ymax = 12000, alpha = 0.3) +
geom_line(data = economics, aes(x = date, y = unemploy)) +
coord_cartesian(y = c(2500, 12000)) +
scale_x_date(expand = c(0, 0))
I might also be inclined to color code the parties as blue and red, so
you could add
scale_fill_manual(values = c("blue", "red"))
to the end of the above call.
Dennis
Dennis
> --
> --
> 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.