posit-dev / positron

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

Possibility to adjust plot scaling (maybe by opening plots in a browser) #3765

Open strengejacke opened 4 months ago

strengejacke commented 4 months ago

What I like about VSCode (and which you cannot achieve as easy in RStudio) is the possibility to open plots in a browser, to adjust the scaling / zoom / dimensions, and then save the plot. This is useful to create plots for presentations or reports, where high DPI is not that crucial (in the latter case, I use ggsave(), trying to find the best looking dimensions/scaling with several attempts).

See this video of the feature I mean. Would be great to have something similar in Positron. Main point is the flexible scaling so that you immediately see the proportions/dimensions of the plot before you copy to clipboard or save to file.

https://github.com/posit-dev/positron/assets/26301769/8ce44e01-f019-4f33-a021-92991396d81f

juliasilge commented 4 months ago

Related to #2270 but a somewhat different possibility

strengejacke commented 4 months ago

I think I'm fine if you can do this inside the plot pane instead of opening a browser. For high resolution I would use ggsave(), anyway. It's mainly to copy plots into word or presentations, where you don't need print quality (which is still often the case, either for internal reports or whatever).

timtmok commented 4 months ago

There are also static (fixed size) plots where we can't control the image size. Those images have a control to change the scaling. I have quickly reused that component to add scaling to dynamic plots and that change is sitting in this branch and needs some polish. I think that setting a custom image size and zooming can help experiment with different results.

There's also the save action in the plots pane that has a preview. The image size can be adjusted and a scaled preview is shown. Perhaps, adding zooming capabilities there would also help.

seeM commented 4 months ago

Sort of requested in https://github.com/posit-dev/positron/issues/3884.

kylebutts commented 4 months ago

I think the desired functionality can be approximated with setting a custom size in the plot viewer.

If you want to export using ggsave, you can use the following. The viewer DPI is set at 144, so the code finds the correct image width and height based on what you set the plot dimensions to be

plot_panel_DPI <- .ps.graphics.defaultResolution
plot_panel_width <- 2000
plot_panel_height <- 1000
DPI <- 300 # Desired DPI of output

# width and height in inches at desired DPI
w <- plot_panel_width / plot_panel_DPI * DPI / plot_panel_DPI
h <- plot_panel_height / plot_panel_DPI * DPI / plot_panel_DPI

# Save the image
ggsave("temp.png", p, width = w, height = h, dpi = DPI)
nstrayer commented 3 months ago

The new HTML widget PR (#4151) that allows opening of HTML widgets in an external browser lays a good foundation for this. Right now that pop-out functionality is restricted to html-based plots but the pattern makes sense here as well.

strengejacke commented 3 months ago

Maybe it's not necessary to have the plot in a new window like you can do in VSCode (see my video above). I think the important thing is:

All this is important only if you copy to clipboard, which I often do for drafts (copy plot directly into word during preparation of manuscript; making presentations/slides...).

See an example for a larger plot resolution, but too small geoms/text:

image

strengejacke commented 3 months ago

I think the desired functionality can be approximated with setting a custom size in the plot viewer.

If you want to export using ggsave, you can use the following. The viewer DPI is set at 144, so the code finds the correct image width and height based on what you set the plot dimensions to be

It's not only about the plot size and DPI - it's about the proportion of plot size/DPI and size of texts/geoms.

MGousseff commented 2 weeks ago

3884 was closed, but I really think being able to detach a plot in its own window is useful. I work with two screens as most of us, i guess, and having the code on one screen and being able to resize and explore the plot on another screen is a feature I really like on other IDEs (Rstudio and intelliJ).

timtmok commented 2 weeks ago

#3884 was closed, but I really think being able to detach a plot in its own window is useful. I work with two screens as most of us, i guess, and having the code on one screen and being able to resize and explore the plot on another screen is a feature I really like on other IDEs (Rstudio and intelliJ).

@MGousseff There is a way to do this after enabling the experimental feature to view a plot in an editor tab. See https://github.com/posit-dev/positron/discussions/5073

Once enabled, you can view the plot in an editor tab then move it into a new window. There's still work to do on it so any feedback is appreciated!

MGousseff commented 2 weeks ago

@timtmok Thank you very much for pointing it : I didn't realize that the very reason to open a plot in an editor tab was to detach it. I enabled the features, it offers what I was asking for, thank you very much, I'll experiment a little and report if I find some feedback potentially useful.