Skip to content

Commit

Permalink
Merge pull request #1247 from Mattriks/Scale_xygroup
Browse files Browse the repository at this point in the history
Scale.{xy}group documentation
  • Loading branch information
bjarthur authored Feb 3, 2019
2 parents a4686b6 + cc68a88 commit 270858c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
21 changes: 21 additions & 0 deletions docs/src/gallery/scales.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,24 @@ df = DataFrame(v1 = randn(10), v2 = randn(10), v3 = randn(10))
p2 = plot(df, x=Col.index, y=Col.value, Scale.x_discrete(levels=names(df)))
hstack(p1,p2)
```

## [`Scale.xgroup`](@ref), [`Scale.ygroup`](@ref)

```@example
using Gadfly, RDatasets
set_default_plot_size(21cm,14cm)
# mpg = miles per gallon
mpg = dataset("ggplot2","mpg")
xlabs = Dict(4=>"4 Cyl", 6=>"6 Cyl", 8=>"8 Cyl")
ylabs = Dict("f"=>"front", "r"=>"rear", "4"=>"4-wheel")
plot(mpg[mpg.Cyl.≠5,:], x=:Cty, y=:Hwy, color=:Class,
xgroup=:Cyl, ygroup=:Drv,
Geom.subplot_grid( Coord.cartesian(xmin=10), Geom.point,
layer(slope=[1], intercept=[0], Geom.abline(color="silver", style=:dash))),
Scale.xgroup(labels=i->xlabs[i], levels=[4,6,8]),
Scale.ygroup(labels=i->ylabs[i], levels=["f","4","r"]),
Guide.xlabel("City miles/gallon by Cylinders"),
Guide.ylabel("Highway miles/gallon by Drive"),
Theme(colorkey_swatch_shape=:circle)
)
```
6 changes: 5 additions & 1 deletion src/scale.jl
Original file line number Diff line number Diff line change
Expand Up @@ -693,13 +693,17 @@ const label = LabelScale

"""
xgroup[(; labels=nothing, levels=nothing, order=nothing)]
A discrete scale for use with [`Geom.subplot_grid`](@ref Gadfly.Geom.subplot_grid).
"""
xgroup(; labels=nothing, levels=nothing, order=nothing) =
DiscreteScale([:xgroup], labels=labels, levels=levels, order=order)

"""
ygroup[(; labels=nothing, levels=nothing, order=nothing)]
"""
A discrete scale for use with [`Geom.subplot_grid`](@ref Gadfly.Geom.subplot_grid).
"""
ygroup(; labels=nothing, levels=nothing, order=nothing) =
DiscreteScale([:ygroup], labels=labels, levels=levels, order=order)

Expand Down
2 changes: 1 addition & 1 deletion test/testscripts/issue1125.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Gadfly, RDatasets

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

iris = dataset("datasets", "iris")
sp = unique(iris[:Species])
Expand Down

0 comments on commit 270858c

Please sign in to comment.