Skip to content
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

Geom.bar together with xmin, xmax #1443

Open
Rudi79 opened this issue May 27, 2020 · 5 comments
Open

Geom.bar together with xmin, xmax #1443

Rudi79 opened this issue May 27, 2020 · 5 comments

Comments

@Rudi79
Copy link

Rudi79 commented May 27, 2020

It seems that gadfly struggles to detect ymax automatically when using Geom.bar together with
xmin, xmax. To see this compare p and p2.

using Gadfly, DataFrames
a=["A","B","C","D","A","C","D","B"]
b=[1,1,1,1,2,2,2,2]
c=[ 12059, 57263, 79003, 13125, 25268, 13291, 17365, 30154]
dt = DataFrame(A=a, B=b, C=c)
dt[!,:xmin] = dt.B .- 0.4
dt[!,:xmax] = dt.B .+ 0.4
p= plot(dt, xmin=:xmin, xmax = :xmax, y =:C, color = :A, Geom.bar(position=:stack))
p2= plot(dt, x=:B, y =:C, color = :A, Geom.bar(position=:stack))
@Mattriks
Copy link
Member

I see what you mean. It looks like in plot p that ymax is being determined from maximum(dt.C), not the stacked max.
Workarounds include:

  • p = plot(..., Coord.cartesian(ymin=0, ymax=2e5))

  •        using Gadfly.Compose
           p2 = plot(..., Theme(bar_spacing=0.2cx))

@Rudi79
Copy link
Author

Rudi79 commented May 27, 2020

Thank you for the quick reply. Right now I am using your first workaround.
Unfortunately, I was not able to get your second workaround to work with x being Dates.

@Mattriks
Copy link
Member

For Dates, Theme(bar_spacing= ) can be plot width/height units, or absolute units, but not plot context units (info about units in Compose). For example, with Dates doing bar_spacing=Day(6)*cx errors in Compose, and bar_spacing=2mm is fine.

@Mattriks Mattriks mentioned this issue May 29, 2020
3 tasks
@Mattriks
Copy link
Member

PR #1446 will fix the first problem above. The second issue (bar_spacing as a Dates.Period type) is an issue involving Compose and/or Base.Dates (i.e. Dates doesn't provide all the maths ops needed to make Compose work for values of type Period.

@Mattriks
Copy link
Member

I think the second issue here has been fixed by GiovineItalia/Compose.jl#409, which introduced new size units: sx, sy.
These will be documented in Gadfly sometime (#1480). To use sx, sy, you'll need to ]add Compose#master.
@Rudi79 can you please test for your plot with Dates.

using Dates, DataFrames, Compose, Gadfly
set_default_plot_size(4inch, 4inch)

D2 = DataFrame(A=["A","B","C","D","A","C","D","B"], B=repeat([Date(1990,1,1), Date(1990,2,1)], inner=4),
 C=[12059, 57263, 79003, 13125, 25268, 13291, 17365, 30154])

p3 = plot(D2, x=:B, y=:C, color=:A, Geom.bar(position=:stack), Theme(bar_spacing=Day(6)*sx))

issue1443

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants