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

visualize() doesn't pass all arguments to ggplot2 functions #504

Closed
wmorgan485 opened this issue Sep 2, 2023 · 2 comments
Closed

visualize() doesn't pass all arguments to ggplot2 functions #504

wmorgan485 opened this issue Sep 2, 2023 · 2 comments

Comments

@wmorgan485
Copy link
Contributor

wmorgan485 commented Sep 2, 2023

< -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->

The problem

Some arguments included in visualize( ) apparently aren't used by ggplot2 functions. This is apparent in Figure 8.34 of the ModernDive textbook, as described below.

Reproducible example

# This code from 
# https://github.com/moderndive/ModernDive_book/blob/master/08-confidence-intervals.Rmd
# is to visualize a bootstrap distribution:

bootstrap_distribution <- read_rds("https://github.com/moderndive/ModernDive_book/blob/master/rds/bootstrap_distribution_balls.rds")

# Visualize bootstrap distribution of p-hat
bootstrap_distribution %>%
  visualize(binwidth = 0.05, boundary = 0.4, color = "white") +
  labs(
    x = "Proportion of 50 balls that were red",
    title = "Bootstrap distribution"
  )

# Based on Figure 8.34 of ModernDive textbook, 
# the `color` argument is passed to ggplot2 functions, 
# but not the `binwidth` and `boundary` arguments, 
# since there are ~3 bins per 0.1 units and no bin has a boundary at 0.4.

reprex::reprex(si = TRUE)
@simonpcouch
Copy link
Collaborator

Thanks for the issue!

A reprex:

library(tidyverse)
library(infer)

bootstrap_distribution <- read_rds("https://github.com/moderndive/ModernDive_book/raw/master/rds/bootstrap_distribution_balls.rds")

# Visualize bootstrap distribution of p-hat
bootstrap_distribution %>%
   visualize(binwidth = 0.05, boundary = 0.4, color = "white") +
   labs(
      x = "Proportion of 50 balls that were red",
      title = "Bootstrap distribution"
   )

Created on 2023-09-05 with reprex v2.0.2

It looks to me like every one of binwidth, boundary, and color here are either ignored or overwritten internally. We can debug on infer:::simulation_layer and infer:::theoretical_layer to see how these do or don't get passed. In this case:

infer/R/visualize.R

Lines 412 to 422 in 6854b6e

if (length(unique(data$stat)) >= 10) {
res <- list(
do.call(
ggplot2::stat_bin,
c(list(mapping = aes(x = stat),
bins = bins,
color = "white",
breaks = bin_breaks),
dots)
)
)

Copy link

This issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.

@github-actions github-actions bot locked and limited conversation to collaborators Nov 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants