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

Enable subplot axis label orientation #1424

Merged
merged 1 commit into from
Apr 25, 2020
Merged
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
2 changes: 1 addition & 1 deletion docs/src/gallery/geometries.md
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ plot(x=rand(25), y=rand(25), Geom.step)
```


## [`Geom.subplot_grid`](@ref)
## [[`Geom.subplot_grid`](@ref)](@id Gallery_Geom.subplot_grid)

```@example
using Gadfly, RDatasets
Expand Down
2 changes: 1 addition & 1 deletion docs/src/gallery/scales.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ p2 = plot(df, x=Col.index, y=Col.value, Scale.x_discrete(levels=names(df)))
hstack(p1,p2)
```

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

```@example
using Gadfly, RDatasets
Expand Down
16 changes: 16 additions & 0 deletions docs/src/man/compositing.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,22 @@ plot(iris, xgroup="Species", x="SepalLength", y="SepalWidth",
[`Geom.subplot_grid`](@ref) can similarly arrange plots vertically, or
even in a 2D grid if there are two shared axes.

Subplots have some inner and outer elements, including Guides and Scales.
For example, place the guide inside `Geom.subplot_grid(...)` to change the subplot labels, or outside to change the outer plot labels.

```@example facet
haireye = dataset("datasets", "HairEyeColor")
palette = ["brown", "blue", "tan", "green"]

plot(haireye, y=:Sex, x=:Freq, color=:Eye, ygroup=:Hair,
Geom.subplot_grid(Geom.bar(position=:stack, orientation=:horizontal),
Guide.ylabel(orientation=:vertical) ),
Scale.color_discrete_manual(palette...),
Guide.colorkey(title="Eye\ncolor"),
Guide.ylabel("Hair color"), Guide.xlabel("Frequency") )
```

More examples can be found in the plot gallery at [Geom.subplot_grid](@ref Gallery_Geom.subplot_grid) and [Scale.{x,y}group](@ref Gallery_Scale.xygroup).

## Stacks

Expand Down
6 changes: 4 additions & 2 deletions src/geom/subplot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,8 @@ function render(geom::SubplotGrid, theme::Gadfly.Theme,
push!(guides, get(geom.guides, Guide.XTicks, Guide.xticks()))

if superplot_aes.xgroup !== nothing
push!(guides, get(geom.guides, Guide.XLabel, Guide.xlabel(xlabels[j])))
gxl = get(geom.guides, Guide.XLabel, Guide.xlabel())
push!(guides, gxl.label=="x" ? Guide.xlabel(xlabels[j], gxl.orientation) : gxl)
end
else
push!(guides, Guide.xticks(label=false))
Expand All @@ -328,7 +329,8 @@ function render(geom::SubplotGrid, theme::Gadfly.Theme,
push!(guides, get(geom.guides, Guide.YTicks, Guide.yticks()))
if superplot_aes.ygroup !== nothing
joff += 1
push!(guides, get(geom.guides, Guide.YLabel, Guide.ylabel(ylabels[i])))
gyl = get(geom.guides, Guide.YLabel, Guide.ylabel())
push!(guides, gyl.label=="y" ? Guide.ylabel(ylabels[i], gyl.orientation) : gyl)
end
else
push!(guides, Guide.yticks(label=false))
Expand Down
4 changes: 2 additions & 2 deletions src/guide.jl
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,7 @@ struct XLabel <: Gadfly.GuideElement
label::Union{(Nothing), AbstractString}
orientation::Symbol
end
XLabel(label; orientation=:auto) = XLabel(label, orientation)
XLabel(label="x"; orientation=:auto) = XLabel(label, orientation)

"""
Guide.xlabel(label, orientation=:auto)
Expand Down Expand Up @@ -977,7 +977,7 @@ struct YLabel <: Gadfly.GuideElement
label::Union{(Nothing), AbstractString}
orientation::Symbol
end
YLabel(label; orientation=:auto) = YLabel(label, orientation)
YLabel(label="y"; orientation=:auto) = YLabel(label, orientation)

"""
Guide.ylabel(label, orientation=:auto)
Expand Down
16 changes: 16 additions & 0 deletions test/testscripts/subplot_grid_guides.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

using Gadfly, RDatasets

set_default_plot_size(14cm, 8cm)

haireye = dataset("datasets","HairEyeColor")
palette = ["brown","blue","tan","green"]

plot(haireye, y=:Sex, x=:Freq, color=:Eye, ygroup=:Hair,
Geom.subplot_grid(Geom.bar(position=:stack, orientation=:horizontal),
Guide.ylabel(orientation=:vertical) ),
Scale.color_discrete_manual(palette...),
Guide.colorkey(title="Eye\ncolor"),
Guide.ylabel("Hair color"), Guide.xlabel("Frequency")
)