Skip to content

Commit

Permalink
color scales working and tested
Browse files Browse the repository at this point in the history
  • Loading branch information
rdboyes committed Apr 12, 2024
1 parent 3f9c932 commit ad2a7f2
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 16 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# TidierPlots.jl updates

# v0.7.0 - 2024-04-12

- Fixes color scales (manual, binned, discrete, and continuous).

# v0.6.5 - 2024-04-09

- Allow use of Julia 1.9 (1.10 is still the recommended version)
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "TidierPlots"
uuid = "337ecbd1-5042-4e2a-ae6f-ca776f97570a"
authors = ["Randall Boyes <[email protected]> and contributors"]
version = "0.6.7"
version = "0.7.0"

[deps]
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ Makie Themes:

Colour Scales:

- `scale_colo[u]r_manual()` - give a list of hex `values` enclosed in `c()` to define a scale
- `scale_colo[u]r_[discrete|continuous]()` - set `palette =` a [Makie palette]( https://docs.makie.org/stable/explanations/colors/index.html#colormaps).
- `scale_color_manual()` - arguments should be given directly in order, accepts anything that can be parsed as a color by Colors.jl (named colors, hex values, etc.)
- `scale_color_[discrete|continuous|binned]()` - set `palette =` a [ColorSchemes.jl palette](https://juliagraphics.github.io/ColorSchemes.jl/stable/catalogue/) as a string or symbol. Also accepts ColorSchemes.jl color scheme objects.

Additional Elements:

Expand Down
5 changes: 2 additions & 3 deletions src/TidierPlots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,8 @@ export scale_x_log10, scale_y_log10, scale_x_log2, scale_y_log2, scale_x_log, sc
export scale_x_logit, scale_y_logit
export scale_x_pseudolog10, scale_y_pseudolog10, scale_x_Symlog10, scale_y_Symlog10
export scale_x_reverse, scale_y_reverse, scale_x_sqrt, scale_y_sqrt
export scale_colour_continuous, scale_color_continuous
export scale_colour_discrete, scale_color_discrete
export scale_colour_manual, scale_color_manual
#export scale_colour_continuous, scale_colour_discrete, scale_colour_manual, scale_colour_binned
export scale_color_continuous, scale_color_discrete, scale_color_manual, scale_color_binned

# transforms

Expand Down
8 changes: 4 additions & 4 deletions src/scales_colour.jl
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,11 @@ end

# scale definitions

scale_colour_manual = color_scale_template("color", color_scale_to_ggoptions, "manual")
#scale_colour_manual = color_scale_template("color", color_scale_to_ggoptions, "manual")
scale_color_manual = color_scale_template("color", color_scale_to_ggoptions, "manual")
scale_colour_discrete = color_scale_template("color", color_scale_to_ggoptions, "discrete")
#scale_colour_discrete = color_scale_template("color", color_scale_to_ggoptions, "discrete")
scale_color_discrete = color_scale_template("color", color_scale_to_ggoptions, "discrete")
scale_colour_continuous = color_scale_template("color", color_scale_to_ggoptions, "continuous")
#scale_colour_continuous = color_scale_template("color", color_scale_to_ggoptions, "continuous")
scale_color_continuous = color_scale_template("color", color_scale_to_ggoptions, "continuous")
scale_colour_binned = color_scale_template("color", color_scale_to_ggoptions, "binned")
#scale_colour_binned = color_scale_template("color", color_scale_to_ggoptions, "binned")
scale_color_binned = color_scale_template("color", color_scale_to_ggoptions, "binned")
3 changes: 2 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ using GLM
using Loess
using KernelDensity
using Colors
using ColorSchemes

# functions to compare two images using a difference hash
# essentially copied from ImageHashes.jl, but package is out of date
Expand All @@ -36,5 +37,5 @@ set_theme!(theme_ggplot2())
include("test_geoms.jl")
include("test_labs.jl")
include("test_lims.jl")
include("test_scale_color.jl")
include("test_scale_colour.jl")
end
18 changes: 13 additions & 5 deletions test/test_scale_colour.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@testset "discrete" begin
t = ggplot(penguins) +
geom_point(aes(x = :bill_depth_mm, y = :bill_length_mm, color = :species)) +
scale_colour_discrete(palette = "julia")
scale_color_discrete(palette = "julia")

colours = ColorSchemes.colorschemes[:julia]

Expand All @@ -19,13 +19,15 @@
)]
)
)
)
)

@test plot_images_equal(t, m)
end

@testset "manual" begin
t = ggplot(penguins) +
geom_point(aes(x = :bill_depth_mm, y = :bill_length_mm, color = :species)) +
scale_colour_manual("red", "white", "blue")
scale_color_manual("red", "white", "blue")

colours = parse.(Colorant, ["red", "white", "blue"])

Expand All @@ -44,12 +46,14 @@ end
)
)
)

@test plot_images_equal(t, m)
end

@testset "continuous" begin
t = ggplot(penguins) +
geom_point(aes(x = :bill_depth_mm, y = :bill_length_mm, color = :bill_depth_mm)) +
scale_colour_continuous(:Purples_5)
scale_color_continuous(:Purples_5)

colours = get(ColorSchemes.colorschemes[:Purples_5],
penguins.bill_depth_mm ./ maximum(penguins.bill_depth_mm))
Expand All @@ -67,12 +71,14 @@ end
)
)
)

@test plot_images_equal(t, m)
end

@testset "binned" begin
t = ggplot(penguins) +
geom_point(aes(x = :bill_depth_mm, y = :bill_length_mm, color = :bill_depth_mm)) +
scale_colour_continuous(:Purples_5)
scale_color_continuous(:Purples_5)

input = penguins.bill_depth_mm

Expand All @@ -91,4 +97,6 @@ end
)
)
)

@test plot_images_equal(t, m)
end

0 comments on commit ad2a7f2

Please sign in to comment.