`options(c("repr.plot.width", "repr.plot.height"))` not handled as expected.
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)".
I am encountering the same issue. When I use options as you have, some options are applied to plots made prior to the options call... Did you find any solution?
No, I was just reporting an issue I saw reported elsewhere. I don't use Jupyter. The fact that there's no fix and yours is the first comment in 2.5 years confirms that as a good decision.
Me being the sole maintainer of IRkernel while no longer using R certainly doesn’t help. I’m still happy to review and merge PRs!
It was a really bad decision by the RStudio people to come up with their own format for R notebooks instead of building on the even then tried-and-true Jupyter notebooks. They could have had so much infrastructure and tooling for free.
But that decision led to most people using their stuff, and little attention going this way. Sad but true.