TidierOrg / TidierPlots.jl

Tidier data visualization in Julia, modeled after the ggplot2 R package.
MIT License
196 stars 7 forks source link

Changing number and length of bins in geom_histogram() #68

Closed AdaemmerP closed 3 months ago

AdaemmerP commented 3 months ago

For geom_histogram(), ggplot2 has the options bins and binwidth to change the number and the length of the bins, respectively. This does not seem to work in TidierPlots.jl:

using Tidier.TidierPlots
using DataFrames

# create data
df = DataFrame(
    x = randn(1000),
)

# histogram with 50 bins
@chain df begin
    ggplot()
    geom_histogram(aes(x=:x), bins=50)
end

# ... and with 100 bins look identical
@chain df begin
    ggplot()
    geom_histogram(aes(x=:x), bins=100)
end

# ... the same holds with binwidth of 5
@chain df begin
    ggplot()
    geom_histogram(aes(x=:x), binwidth=5)
end

# ... and with binwidth of 10
@chain df begin
    ggplot()
    geom_histogram(aes(x=:x), binwidth=10)
end

I am using TidierPlots v.0.5.5.

rdboyes commented 3 months ago

Thanks for reporting this! I've fixed the bins option in the development version (as of https://github.com/TidierOrg/TidierPlots.jl/commit/eaabd2e3a54ac2932c4cb5b20c07c1d27077fa3a), but haven't gotten to binwidth yet:

df = DataFrame(
    x = randn(1000),
)
g1 = ggplot(df) + geom_histogram(aes(x = :x), bins = 10)
g2 = ggplot(df) + geom_histogram(aes(x = :x), bins = 100)

g1

g2

g2

g1

I'm leaving this open until binwidth is implemented

rdboyes commented 3 months ago

binwidth is not an option in Makie's hist plot, making this more difficult than expected. binwidth is not likely to be implemented in the near term, but may be revisited

AdaemmerP commented 3 months ago

Great, thank you!