GiovineItalia / Gadfly.jl

Crafty statistical graphics for Julia.
http://gadflyjl.org/stable/
Other
1.9k stars 250 forks source link

Hair as Lolipop chart #1518

Open hewsond opened 3 years ago

hewsond commented 3 years ago

Hi,

Fantastic library.

I was playing around with this and noticed that hair plots couldn't work as a lolipop chart despite having the option to set the intercept. e.g.

x= 1:10
pc = plot(x=x, y=x.^2, Geom.hair(intercept=(x.^2)./2), Geom.point)

Having a play around with the code I was able to implement the following by changing the library.

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))
pc = 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])

lolipop

I was wondering would this be a feature that that you'd want added to the Geom.hair?

If so I can create a pull request.

bjarthur commented 3 years ago

so the problem is that intercept currently has to be a scalar, and you want a vector? seems like a good feature to have. yes, please submit a PR. thanks!

Mattriks commented 3 years ago

Note that there's also Geom.segment which got an update in #1465. Geom.segment could be used to do the lower plots above (albeit both x/xend or y/yend need to be specified). In Grammar of Graphics, Geom.hair = Geom.segment + Stat.hair.