erocoar / ggpol

🌍 Parliament diagrams and more for ggplot2
https://erocoar.github.io/ggpol/
Other
104 stars 10 forks source link

facet_share not working #14

Open guivivi opened 1 year ago

guivivi commented 1 year ago

Dear Frederik, thank you very much for your nice package. I am opening this issue because the example of facet_share from https://erocoar.github.io/ggpol/ is not working anymore. Specifically, I am getting this error:

df <- data.frame(sex = sample(c("M", "F"), 1000, replace = TRUE),
                 age = rnorm(1000, 45, 12))

df$age_bins <- cut(df$age, 15)
df$count <- 1
df <- aggregate(count ~ sex + age_bins, data = df, length)

df_h <- df
df_h$count <- ifelse(df_h$sex == "F", df_h$count * -1, df_h$count)

ggplot(df_h, aes(x = age_bins, y = count, fill = sex)) + 
  geom_bar(stat = "identity") +
  facet_share(~sex, dir = "h", scales = "free", reverse_num = TRUE) + 
  coord_flip()

Error in unit(c(as.numeric(axes$y$left[[1]]$children$axis$widths[[tick_idx]]), : 'list' object cannot be coerced to type 'double'

Do you know how to fix it? I was trying to update with new data a plot that I created with facet_share this time last year, but I cannot due to this facet_share problem.

Thank you in advance for any comment you might provide.

Kind regards,

Guillermo