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.rect #993

Merged
merged 1 commit into from
Apr 30, 2017
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
21 changes: 15 additions & 6 deletions docs/src/lib/geoms/geom_rectbin.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
```@meta
Author = "Daniel C. Jones"
Author = "Daniel C. Jones, Mattriks"
```

# Geom.rectbin
Expand All @@ -9,30 +9,39 @@ Draw colored rectangles.
## Aesthetics
* color

Either
Either (for `Geom.rect`)

* x_min
* x_max
* y_min
* y_max

Or
Or (for `Geom.rectbin`)

* x
* y

In the former case, rectangles defined by `x_min`, `x_max`, `y_min`, `y_max`
are drawn, in the latter, equal sizes squares are centered at `x` and `y`
For `Geom.rect`, rectangles defined by `x_min`, `x_max`, `y_min`, `y_max`
are drawn.
For `Geom.rectbin`, equal sizes squares are centered at `x` and `y`
positions.

## Examples

```@setup 1
using RDatasets
using DataFrames, RDatasets
using Gadfly
Gadfly.set_default_plot_size(14cm, 8cm)
```

```@example 1
plot(dataset("Zelig", "macro"), x="Year", y="Country", color="GDP", Geom.rectbin)
```

```@example 1
theme1 = Theme(default_color=RGBA(0, 0.75, 1.0, 0.5))
D = DataFrame(x=[0.5,1], y=[0.5,1], x1=[0,0.5], y1=[0,0.5], x2=[1,1.5], y2=[1,1.5])
pa = plot(D, x=:x, y=:y, Geom.rectbin, theme1)
pb = plot(D, xmin=:x1, ymin=:y1, xmax=:x2, ymax=:y2, Geom.rect, theme1)
hstack(pa, pb)
```
6 changes: 4 additions & 2 deletions src/geom/rectbin.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ function RectangularBinGeometry(
RectangularBinGeometry(default_statistic, tag)
end

rect() = RectangularBinGeometry(Gadfly.Stat.Identity())

const rectbin = RectangularBinGeometry

function histogram2d(; xbincount=nothing, xminbincount=3, xmaxbincount=150,
Expand Down Expand Up @@ -40,7 +42,7 @@ element_aesthetics(::RectangularBinGeometry) =
function render(geom::RectangularBinGeometry, theme::Gadfly.Theme, aes::Gadfly.Aesthetics)

default_aes = Gadfly.Aesthetics()
default_aes.color = PooledDataArray(RGB{Float32}[theme.default_color])
default_aes.color = PooledDataArray(RGBA{Float32}[theme.default_color])
aes = inherit(aes, default_aes)

Gadfly.assert_aesthetics_defined("RectangularBinGeometry", aes, :xmin, :xmax, :ymin, :ymax)
Expand All @@ -61,7 +63,7 @@ function render(geom::RectangularBinGeometry, theme::Gadfly.Theme, aes::Gadfly.A
if length(aes.color) == n
cs = aes.color
else
cs = Array{RGB{Float32}}(n)
cs = Array{RGBA{Float32}}(n)
for i in 1:n
cs[i] = aes.color[((i - 1) % length(aes.color)) + 1]
end
Expand Down
12 changes: 10 additions & 2 deletions test/rectbin.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@

using Gadfly, DataArrays, RDatasets
using DataFrames, Gadfly

# using RDatasets
# plot(dataset("Zelig", "macro"), x="Year", y="Country", color="GDP", Geom.rectbin)

D = DataFrame(x=[0.5,1], y=[0.5,1], x1=[0,0.5], y1=[0,0.5], x2=[1,1.5], y2=[1,1.5])
pa = plot(D, x=:x, y=:y, Geom.rectbin)
pb = plot(D, xmin=:x1, ymin=:y1, xmax=:x2, ymax=:y2, Geom.rect)
hstack(pa,pb)


plot(dataset("Zelig", "macro"), x="Year", y="Country", color="GDP", Geom.rectbin)