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

options(c("repr.plot.width", "repr.plot.height")) not handled as expected. #59

Open
dmurdoch opened this issue Jun 21, 2022 · 0 comments

Comments

@dmurdoch
Copy link

This StackOverflow question: https://stackoverflow.com/q/72698223 illustrates what looks like a bug in the display of graphics. This script:

temp <- mtcars[, 1:3]
colnames(temp) <- c("x1", "z", "y1")

plotting_function <- function(data_to_vis) {
  
  p1 <- ggplot(data_to_vis, aes(x=x1, y=y1)) +
    geom_point(size = 3)       
  options(repr.plot.width = 5, repr.plot.height = 5)     
  print(p1)
  p2 <- ggplot(data_to_vis, aes(x=x1, y=y1)) +
    geom_point() +
    facet_wrap(~z) +
    theme(aspect.ratio = 1)
  options(repr.plot.width = 20, repr.plot.height = 20) 
  print(p2)
}

library(ggplot2)
plotting_function(temp)

uses the 2nd options() setting to set the width and height of both plots. To get them to appear as intended, the first setting needs to be moved after the print(p1) statement.

This was tested on the R kernel at https://jupyter.org/try, which reports "The version of the notebook server is: 6.4.10", "Current kernel information: R version 4.1.2 (2021-11-01)".

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

1 participant