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

Differences in behaviour between the ggplot and tidier implementations of geom_bar() and geom_col(). #40

Closed
JasonPekos opened this issue Oct 20, 2023 · 2 comments

Comments

@JasonPekos
Copy link

JasonPekos commented Oct 20, 2023

Looking at the R bar plot documentation, there are significant differences between the Julia and R bar plot implementations. Some of these — related to sideways bar plots — are pretty significant.


Consider the following ggplot (R) code:

ggplot(mpg) + geom_bar(aes(y = class))

geom_bar-3

The corresponding Julia code seems like it should be:

using RDatasets
using TidierPlots

cars = dataset("datasets", "mtcars")

ggplot(cars) + 
    geom_bar(@aes(y = Model))

But Tidier fails here, requiring an x aesthetic.

geom_col() is a little weirder. In R:

ggplot(mpg, aes(y = class, x = cyl)) + geom_col()

g

However in TidierPlots:

ggplot(cars) + 
    geom_col(@aes(y = Model, x = Cyl))

plot_147

I think at least the geom_col behaviour is concerning.

@rdboyes
Copy link
Member

rdboyes commented Feb 26, 2024

Finally making progress on this issue - in 0.6 (not released yet):

using TidierPlots
using DataFrames

df = DataFrame(cat = ["left", "left", "left",
 "middle", "middle", "middle", "right", "right", "right"],
       height = 0.1:0.1:0.9,
       grp = [1, 2, 3, 1, 2, 3, 1, 2, 3],
       grp1 = [1, 2, 2, 1, 1, 2, 1, 1, 2],
       grp2 = [1, 1, 2, 1, 2, 1, 1, 2, 1]
)

ggplot(df, yticks = (1:3, ["bottom", "middle", "top"])) + 
    geom_col(@aes(cat, height, color = grp, bar_labels = height), 
        position = "dodge", direction = "x") + labs(title = "Dodged Bars") + 
    theme_dark()

download

@rdboyes
Copy link
Member

rdboyes commented Feb 27, 2024

The geom_bar behaviour is fixed now, but I think the geom_col behaviour in R is actually ... bad? It's not actually clear to me what the plot in the example should look like in order to make sense. In any case:

using TidierPlots
using DataFrames
using CSV
    
cars = CSV.read("scratch/auto-mpg.csv", DataFrame)
    
ggplot(cars) + 
    geom_bar(@aes(y = class))

Produces (in 0.6.0):
download

@rdboyes rdboyes closed this as completed Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants