Skip to content

Commit

Permalink
rename groupby to group_by in density/3
Browse files Browse the repository at this point in the history
  • Loading branch information
pnezis committed Dec 22, 2023
1 parent 26f9dd8 commit f471c7c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Tucan.scatter(:iris, "petal_width", "petal_length")

- Flipped `:orient` semantics for `Tucan.bar/4`
- Rename `:group` option to `:group_by` in `Tucan.stripplot/3` for consistency.
- Rename `:groupby` option to `:group_by` in `Tucan.density/3` for consistency.

### Deprecated

Expand Down
18 changes: 10 additions & 8 deletions lib/tucan.ex
Original file line number Diff line number Diff line change
Expand Up @@ -419,18 +419,18 @@ defmodule Tucan do
doc: "Whether the density plot will be filled or not, default to `true` if not set",
section: :style
],
groupby: [
group_by: [
type: {:list, :string},
doc: """
The data fields to group by. If not specified, a single group containing all data
objects will be used. This is applied only on the density transform.
In most cases you only need to set `color_by` which will automatically handle the
density transform grouping. Use `groupby` only if you want to manually post-process
In most cases you only need to set `:color_by` which will automatically handle the
density transform grouping. Use `:group_by` only if you want to manually post-process
the generated specification, or if you want to apply grouping by more than one
variable.
If both `groupby` and `color_by` are set then only `groupby` is used for grouping
If both `:group_by` and `:color_by` are set then only `:group_by` is used for grouping
the density transform and `color_by` is used for encoding the color.
""",
dest: :density_transform
Expand Down Expand Up @@ -541,11 +541,11 @@ defmodule Tucan do
> Tucan.density(:penguins, "Body Mass (g)", color_by: "Species", fill_opacity: 0.2)
> ```
>
> Alternatively you should use the `:groupby` option in order to group the density
> Alternatively you should use the `:group_by` option in order to group the density
> transform by the `Species` field and then apply the `color_by/3` function:
>
> ```elixir
> Tucan.density(:penguins, "Body Mass (g)", groupby: ["Species"], fill_opacity: 0.2)
> Tucan.density(:penguins, "Body Mass (g)", group_by: ["Species"], fill_opacity: 0.2)
> |> Tucan.color_by("Species")
> ```
Expand All @@ -570,11 +570,11 @@ defmodule Tucan do
```
You can also combine it with `facet_by/4` in order to draw a different plot for each value
of the grouping variable. Notice that we need to set the `:groupby` variable in order
of the grouping variable. Notice that we need to set the `:group_by` variable in order
to correctly calculate the density plot per field's value.
```tucan
Tucan.density(:penguins, "Body Mass (g)", groupby: ["Species"])
Tucan.density(:penguins, "Body Mass (g)", group_by: ["Species"])
|> Tucan.color_by("Species")
|> Tucan.facet_by(:column, "Species")
```
Expand Down Expand Up @@ -625,7 +625,9 @@ defmodule Tucan do

transform_opts =
Tucan.Options.take_options(opts, @density_opts, :density_transform)
|> Keyword.drop([:group_by])
|> Keyword.merge(density: field)
|> Tucan.Keyword.put_not_nil(:groupby, opts[:group_by])
|> Tucan.Keyword.put_new_conditionally(:groupby, [opts[:color_by]], fn ->
opts[:color_by] != nil
end)
Expand Down
4 changes: 2 additions & 2 deletions test/tucan_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@ defmodule TucanTest do
minsteps: 5,
maxsteps: 30,
cumulative: true,
groupby: ["species"]
group_by: ["species"]
) ==
expected
end
Expand Down Expand Up @@ -956,7 +956,7 @@ defmodule TucanTest do
)
|> Vl.encode_field(:color, "species")

assert Tucan.density(@iris_dataset, "petal_width", groupby: ["other"], color_by: "species") ==
assert Tucan.density(@iris_dataset, "petal_width", group_by: ["other"], color_by: "species") ==
expected
end
end
Expand Down

0 comments on commit f471c7c

Please sign in to comment.