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

Added ability for intercept in geom.hair to take vector to function as lolipop #1519

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Each release typically has a number of minor bug fixes beyond what is listed her
* Add "vertical" orientation for `Geom.ribbon` (#1513)
* Support one-length aesthetics for `Geom.polygon` and `Geom.ribbon` (#1511)
* Enable `color` grouping for `Geom.density2d` (#1508)
* Add ability for `intercept` to be a vector in `Geom.hair` to function as a lolipop chart (#1518)

# Version 1.3.1

Expand Down
8 changes: 6 additions & 2 deletions docs/src/gallery/geometries.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,13 +271,17 @@ hstack(p1,p2)

```@example
using Gadfly
set_default_plot_size(21cm, 8cm)
set_default_plot_size(21cm, 16cm)
x= 1:10
s = [-1,-1,1,1,-1,-1,1,1,-1,-1]
pa = plot(x=x, y=x.^2, Geom.hair, Geom.point)
pb = plot(x=s.*(x.^2), y=x, color=string.(s),
Geom.hair(orientation=:horizontal), Geom.point, Theme(key_position=:none))
hstack(pa, pb)
pc = plot(x=x, y=x.^2, Geom.hair(intercept=(x.^2)./2), Geom.point)
pd = plot(x=s.*(x.^2), y=x, color=string.(s),
Geom.hair(orientation=:horizontal, intercept=s.*(x.^2)/2), Geom.point,
Theme(key_position=:none))
gridstack([pa pb; pc pd])
```


Expand Down
12 changes: 10 additions & 2 deletions src/statistics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2004,10 +2004,18 @@ function apply_statistic(stat::HairStatistic,
aes::Gadfly.Aesthetics)
if stat.orientation == :vertical
aes.xend = aes.x
aes.yend = fill(stat.intercept, length(aes.y))
if length(stat.intercept) == length(aes.x)
aes.yend = stat.intercept
else
aes.yend = fill(stat.intercept, length(aes.y))
end
else
aes.yend = aes.y
aes.xend = fill(stat.intercept, length(aes.x))
if length(stat.intercept) == length(aes.x)
aes.xend = stat.intercept
else
aes.xend = fill(stat.intercept, length(aes.x))
end
end
end

Expand Down
8 changes: 6 additions & 2 deletions test/testscripts/hair.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

using Gadfly

set_default_plot_size(6inch, 3inch)
set_default_plot_size(6inch, 6inch)


x= 1:10
s = [-1,-1,1,1,-1,-1,1,1,-1,-1]
pa = plot(x=x, y=x.^2, Geom.hair, Geom.point)
pb = plot(x=s.*(x.^2), y=x, Geom.hair(orientation=:horizontal), Geom.point, color=string.(s), Theme(key_position=:none))
hstack(pa, pb)
pc = plot(x=x, y=x.^2, Geom.hair(intercept=(x.^2)./2), Geom.point)
pd = plot(x=s.*(x.^2), y=x, color=string.(s),
Geom.hair(orientation=:horizontal, intercept=s.*(x.^2)/2), Geom.point,
Theme(key_position=:none))
gridstack([pa pb; pc pd])