posit-dev / positron

Positron, a next-generation data science IDE
https://positron.posit.co
Other
2.82k stars 90 forks source link

The image output is overlapping in plot viewer when using ggExtra and ggplot packages #5346

Open stormrage009 opened 1 week ago

stormrage009 commented 1 week ago

System details:

Positron and OS details:

Positron Version: 2024.11.0 (system setup) build 140 Code - OSS Version: 1.93.0 Commit: e0d844b031f95acbf89f234a2cce2af9b6721f6c Date: 2024-10-31T14:14:22.699Z Electron: 20.15.1 ElectronBuildId: 12.4.254.20-electron.0 Chromium: Windows_NT x64 10.0.26120 Node.js: undefined V8: undefined OS: undefined

Interpreter details:

R 4.4.2

Describe the issue:

When I use the ggExtra and ggplot packages for plotting, the images overlap in the plot viewer when there was another plot in plot viewer already!

Steps to reproduce the issue:

Code to reproduce issue:

library(ggExtra) library(ggplot2) set.seed(30) df <- data.frame(x = rnorm(500, 50, 10), y = runif(500, 0, 50)) p2 <- ggplot(df, aes(x, y)) + geom_point() df2 <- data.frame(x = c(rnorm(250, 50, 10), rnorm(250, 100, 10)), y = runif(500, 0, 50)) p2 <- ggplot(df2, aes(x, y)) + geom_point() ggMarginal(p2)` In Psoitron, the output of the above code is as follows:

Image

Expected or desired behavior:

And the correct output should be two plots:

Image

juliasilge commented 1 week ago

Here is the code to generate this problem, which I can reproduce in a regular .R file (not just running the whole chunk at once from .qmd or similar):

library(ggExtra)
library(ggplot2)
set.seed(30)
df <- data.frame(x = rnorm(500, 50, 10), y = runif(500, 0, 50))
p2 <- ggplot(df, aes(x, y)) + geom_point()
ggMarginal(p2, type = "boxplot")
ggMarginal(p2, type = "histogram")

I took a quick look at ggExtra and I think it has to do with the print method here: https://github.com/daattali/ggExtra/blob/9d91043b5cead332559cbdf874e1bf935af0489e/R/ggMarginal.R#L203

juliasilge commented 1 week ago

We're not drawing a new page but grDevices::dev.interactive() looks to evaluate to FALSE in both RStudio and Positron consoles? Not sure what's going on.

Check out the newpage behavior:

library(ggExtra)
library(ggplot2)
set.seed(30)
df <- data.frame(x = rnorm(500, 50, 10), y = runif(500, 0, 50))
p2 <- ggplot(df, aes(x, y)) + geom_point()
p <- ggMarginal(p2, type = "boxplot")
print(p, newpage = TRUE)
p <- ggMarginal(p2, type = "histogram")
print(p, newpage = TRUE)
stormrage009 commented 1 week ago

We're not drawing a new page but grDevices::dev.interactive() looks to evaluate to FALSE in both RStudio and Positron consoles? Not sure what's going on.我们没有绘制新页面,但grDevices::dev.interactive()在 RStudio 和 Positron 控制台中都显示为FALSE?不知道是怎么回事。

Check out the newpage behavior:查看新页面行为:

library(ggExtra) library(ggplot2) set.seed(30) df <- data.frame(x = rnorm(500, 50, 10), y = runif(500, 0, 50)) p2 <- ggplot(df, aes(x, y)) + geom_point() p <- ggMarginal(p2, type = "boxplot") print(p, newpage = TRUE) p <- ggMarginal(p2, type = "histogram") print(p, newpage = TRUE)

Thanks for reply. When i ues code print(p, newpage = TRUE), the output is correct. However, this approach is still a bit cumbersome. Is it possible to fix or improve this issue in future versions of Positron, so that we can output the correct result without using the code print(p, newpage = TRUE)?

juliasilge commented 1 week ago

Yep, sure thing @stormrage009! I have moved this issue to triage so we can prioritize when to dig deeper to find the cause and then create a solution.

stormrage009 commented 1 week ago

Yep, sure thing @stormrage009! I have moved this issue to triage so we can prioritize when to dig deeper to find the cause and then create a solution.

Thank you very much for the quick response:)