Possibility to open plots in a browser to adjust scaling
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
Related to #2270 but a somewhat different possibility
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).
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.
Sort of requested in https://github.com/posit-dev/positron/issues/3884.
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)
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.
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:
- custom size: to avoid that plot is "pixelated" when you copy to clipboard and paste into, e.g., power point. This is already possible.
- scaling: when you increase the custom size for a better quality of the plot, the geoms and axis texts etc. become very small. It would be good to have an option to adjust the scaling then.
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:
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.
#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).
#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!
@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.
The scaling options in the video above come from httpgd: https://nx10.github.io/httpgd/
We've added our own scaling options now, under "Fit":
Does this do what folks need?
No, that's a zoom, not a scaling. I would like to keep the resolution (width * height in pixel), but change the proportion of the font/axis/line sizes. Similar to changing a theme's base_size:
library(ggplot2)
ggplot(iris, aes(Sepal.Width, Sepal.Length, color = Species)) +
geom_point() +
theme_bw(base_size = 11)
ggplot(iris, aes(Sepal.Width, Sepal.Length, color = Species)) +
geom_point() +
theme_bw(base_size = 21)
The use case is working in Positron, creating plots, copy plots into Word/Powerpoint, resize plot to fit to size of page / slide, and then the font should be large enough to be readable. Therefore, you need to change the base_size of plots, so proportions are good-looking after resizing the plot on a slide.
I think one use case that #3884 does not cover is to have the detached editor window/plot pane always contain the latest plot, as the integrated pane now does - typically I will have this on a second screen to have a good view of whatever I am iterating on.
It works now with e.g. plotly plots, which turn up in the Plots pane but can be sent to a browser window. Having something similar for standard plots would be great. Ideally this would be just detaching the entire plots pane, which also includes the history filmstrip.
Ideally this would be just detaching the entire plots pane, which also includes the history filmstrip.
This is tracked in https://github.com/posit-dev/positron/issues/7054 ! Please upvote so we know you're interested in this feature.
Is there any update on this feature? Since Positron is based on VScode, why can't plots be shown in a browser through httpgd?
Thanks!