-
Notifications
You must be signed in to change notification settings - Fork 26
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
annotation layers for thickness and dots scales #183
Comments
I think that this could work, and would be helpful. This works as a very simple version (without being robust to missingness in x) binwidth = find_dotplot_binwidth(na.omit(x), maxheight = 2/3*diff(range(x, na.rm = TRUE)), heightratio = 1) bin_df = bin_dots(x = x, y = 0, binwidth = binwidth, heightratio = 1) bin_df %>% |
This version seems to be robust to missingness in x library(tidyverse) x = penguins$bill_length_mm binwidth = find_dotplot_binwidth(na.omit(x), maxheight = 2/3*diff(range(x, na.rm = TRUE)), heightratio = 1) bin_df = bin_dots(x = na.omit(x), y = 0, binwidth = binwidth, heightratio = 1) bin_df %>% |
Thanks, this will be helpful for updating the docs of bin_dots / find_dotplot_binwidth to help other folks with this problem! |
If anyone (@ASKurz ?) is interested in trying this out, there is now a prototype implementation of what I am provisionally calling "sub-guides" for annotating thickness and dot counts. You can test it on the "subguide" branch via: remotes::install_github("mjskay/ggdist@subguide") Some examples: library(ggplot2)
library(ggdist)
library(distributional)
df = data.frame(
x = c(dist_gamma(1:2,1:2), dist_normal(2:3,0.75)),
group = c("a","a","b","b"),
subgroup = c("d","e","d","e")
)
df |>
ggplot(aes(xdist = x, y = group, fill = subgroup)) +
stat_dots(subguide = "count", position = "dodge", color = NA, justification = 0.5, quantiles = 50) df |>
ggplot(aes(xdist = x, y = group, fill = subgroup)) +
stat_dots(
subguide = subguide_count(title = "count", label_side = "left"),
position = "dodgejust",
color = NA,
quantiles = 50,
height = 0.91
) +
scale_x_continuous(expand = expansion(add = 0.6)) df |>
ggplot(aes(xdist = x, y = group, fill = subgroup)) +
stat_slabinterval(
subguide = subguide_axis(label_side = "outside", title = "density"),
position = "dodgejust",
height = 0.9,
scale = 0.9,
side = "top"
) +
scale_x_continuous(expand = expansion(add = 1)) df |>
ggplot(aes(xdist = x, y = group, fill = subgroup)) +
stat_slabinterval(
subguide = subguide_outside(title = "density"),
position = "dodgejust",
height = 0.9,
scale = 0.8,
side = "top",
normalize = "groups"
) +
scale_y_discrete(breaks = NULL) +
ylab(NULL) +
theme(plot.margin = margin(5.5, 5.5, 5.5, 50)) Positioning can be a bit finicky, but I'm not sure there's any way to make that easier without fundamental changes to ggplot2 (see e.g. tidyverse/ggplot2#5609) |
But anyways, so far I really like what I'm seeing. |
So I guess this issue is independent from using similar scales across facets? Notice the different y-axis scales in the left and right facets expand_grid(
group = c("a","a","b"),
subgroup = c("d","d","e"),
reps = 1:50
) %>%
mutate(x = rnorm(n(), group=="a", 1+(subgroup == "d"))) %>%
ggplot(aes(x = x, fill = subgroup)) +
ggdist::geom_dots(
subguide = ggdist::subguide_count(title = "count", label_side = "left"),
position = "dodgejust",
color = NA,
height = 0.91
) +
scale_x_continuous(expand = expansion(add = 0.6)) +
facet_grid(cols = vars(group)) |
Yeah the faceting issue is separate unfortunately; trickier to address. See #191. |
I think the faceting issue would also apply to my use cases. |
For faceting, if the chart isn't dynamic you can just choose a binwidth manually and then everything should line up --- the inconsistency is caused by the automatic binwidth algorithm picking different binwidths in different charts. |
no complaints so far, so this is on master now and will be in the next release. |
Pinging off of #182, it occurred to me a solution for this would be to add a layer that is capable of adding subscale axis labels for thickness and dots geoms. It would be like a legend, but drawn directly on the chart.
This requires knowing geom settings and data from a slab or dots geom, so this would probably have to be tied to the geom. I initially thought a separate layer makes sense, but perhaps an option on a slab is more sensible, because of the inherent ties to the normalization settings of the geom (and, in the case of dots, it would have to be computed after binwidth is determined by the grob, so can't be on a separate layer at all). Something like
stat_slab(..., thickness_guide = ...)
orstat_slab(..., subaxis = ...)
orstat_slab(..., subguide = ...)
...The text was updated successfully, but these errors were encountered: