Skip to content

Commit

Permalink
adds geom_hline and geom_vline support
Browse files Browse the repository at this point in the history
  • Loading branch information
rdboyes committed Feb 21, 2024
1 parent c3e5ed0 commit 9864ea0
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
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 <33524191+rdboyes@users.noreply.github.com> and contributors"]
version = "0.5.5"
version = "0.5.6"

[deps]
AlgebraOfGraphics = "cbdf2221-f076-402e-a563-3d30da359d67"
Expand Down
4 changes: 3 additions & 1 deletion src/TidierPlots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ include("show.jl")
include("util.jl")

include("geoms/geom_template.jl")

include("geoms/geom_bar.jl")
include("geoms/geom_boxplot.jl")
include("geoms/geom_contour.jl")
include("geoms/geom_errorbar.jl")
include("geoms/geom_density.jl")
include("geoms/geom_errorbar.jl")
include("geoms/geom_hvline.jl")
include("geoms/geom_path.jl")
include("geoms/geom_point.jl")
include("geoms/geom_smooth.jl")
Expand Down
28 changes: 12 additions & 16 deletions src/geoms/geom_hvline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ function geom_hline(args...; kwargs...)

args_dict["geom_name"] = "geom_hline"

if haskey(args_dict, "yintercept")
args_dict["data"] = DataFrame(Numeric = args_dict["yintercept"])
aes_dict["yintercept"] = :Numeric
end

return build_geom(aes_dict, args_dict,
["yintercept"], # required aesthetics
Makie.HLines, # function for visual layer
Expand All @@ -14,30 +19,21 @@ function geom_vline(args...; kwargs...)

args_dict["geom_name"] = "geom_vline"

if haskey(args_dict, "xintercept")
args_dict["data"] = DataFrame(Numeric = args_dict["xintercept"])
aes_dict["xintercept"] = :Numeric
end

return build_geom(aes_dict, args_dict,
["xintercept"], # required aesthetics
Makie.VLines, # function for visual layer
mapping()) # function for analysis layer
end

function geom_hline(plot::GGPlot, args...; kwargs...)
aes_dict, args_dict = extract_aes(args, kwargs)

args_dict["geom_name"] = "geom_hline"

return plot + build_geom(aes_dict, args_dict,
["yintercept"], # required aesthetics
Makie.HLines, # function for visual layer
mapping()) # function for analysis layer
return plot + geom_hline(args...; kwargs...)
end

function geom_vline(plot::GGPlot, args...; kwargs...)
aes_dict, args_dict = extract_aes(args, kwargs)

args_dict["geom_name"] = "geom_vline"

return plot + build_geom(aes_dict, args_dict,
["xintercept"], # required aesthetics
Makie.VLines, # function for visual layer
mapping()) # function for analysis layer
return plot + geom_vline(args...; kwargs...)
end
18 changes: 10 additions & 8 deletions src/interop.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,16 @@ function Layers(plot::GGPlot)
@error("No data found for $name. Either specify a data argument for each geom or specify a default for the ggplot.")
end

data_with_na = DataFrame(data.data)
data_without_na = dropmissing(DataFrame(data.data), unique(String.(values(geom.aes))))

if nrow(data_with_na) != nrow(data_without_na)
name = geom.args["geom_name"]
number = nrow(data_with_na) - nrow(data_without_na)
@warn("$name will not plot $number rows with missing values.")
data = AlgebraOfGraphics.data(data_without_na)
if length(geom.aes) != 0
data_with_na = DataFrame(data.data)
data_without_na = dropmissing(DataFrame(data.data), unique(String.(values(geom.aes))))

if nrow(data_with_na) != nrow(data_without_na)
name = geom.args["geom_name"]
number = nrow(data_with_na) - nrow(data_without_na)
@warn("$name will not plot $number rows with missing values.")
data = AlgebraOfGraphics.data(data_without_na)
end
end

push!(layers, geom_to_layer(geom, data, plot.axis_options))
Expand Down

2 comments on commit 9864ea0

@rdboyes
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/101372

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.5.6 -m "<description of version>" 9864ea0ef1c464497ab7fb4d084e99bca2984e76
git push origin v0.5.6

Also, note the warning: Version 0.5.6 skips over 0.5.5
This can be safely ignored. However, if you want to fix this you can do so. Call register() again after making the fix. This will update the Pull request.

Please sign in to comment.