-
Notifications
You must be signed in to change notification settings - Fork 250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add vertical bands like vspan() in Plots.jl #1174
Comments
this produces identical output:
the only problem is that |
Thanks @bjarthur ! In my specific case, that it is a problem: I am judging the behavior of a time-series depending around the edges of those boxes. So I would need to specify it the size in the original plot, e.g. |
using RDatasets, Gadfly
Dp = dataset("ggplot2","presidential")[3:end,:]
De = dataset("ggplot2","economics")
De[:Unemploy] /= 10^3
Dp[:y1] = 0; Dp[:y2] = 12
theme(x) = style(default_color=parse(Colors.Colorant, x))
p = plot(Dp, xmin=:Start, xmax=:End, ymin=:y1, ymax=:y2, Geom.rect, color=:Party,
layer(De, x=:Date, y=:Unemploy, Geom.line, order=2, theme("black")),
Scale.color_discrete_manual("deepskyblue", "lightcoral"),
Coord.cartesian(xmin=Date("1965-01-01"), ymax=12),
Guide.xlabel("Time"), Guide.ylabel("Unemployment (x10³)"), Guide.colorkey(title=""),
Theme(key_position=:top)
) |
And here is similar plot code in R, for comparison: p = ggplot(presidential)+geom_rect(aes(xmin=start, xmax=end, ymin=-Inf, ymax=Inf, fill=party))+
geom_line(data=economics, aes(x=date, y=unemploy))+
scale_fill_manual(values=c("deepskyblue", "lightcoral"))+
coord_cartesian(xlim=as.Date(c("1965-01-01", "2009-12-31")), ylim=c(0,12000), expand=F)+
labs(x="Time", y="Unemployment", fill="")+
theme(legend.position="top") |
And another way, which uses using Compose, DataFrames, Gadfly
srand(123)
df = DataFrame(year=1990:2000, x = rand(11))
p = plot(df, x=:year, y=:x, xintercept=[1993.5, 1995.5, 1997.5],
Geom.line, Geom.point, Geom.vline(color="lightgrey", size=[1cx])) |
of course! i should've thought of that!! @miguelmorin if this solves your problem please close this issue |
Thanks @Mattriks ! Your solution with |
I would like to easily plot vertical bands, e.g. as a background for a recession in a time-series plot.
Plots.jl
hasvspan()
. In Gadfly, it requires a lot of code and mixes the color of the bands with the color of the time-series line.For reference, the code is below, copied from StackOverflow:
The text was updated successfully, but these errors were encountered: