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

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

Open
strengejacke opened this issue Jul 1, 2024 · 11 comments
Labels
area: plots Issues related to Plots category. enhancement New feature or request support theme: app builder

Comments

@strengejacke
Copy link

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.

plot_browser.mp4
@strengejacke strengejacke added the enhancement New feature or request label Jul 1, 2024
@juliasilge juliasilge added the area: plots Issues related to Plots category. label Jul 1, 2024
@juliasilge
Copy link
Contributor

Related to #2270 but a somewhat different possibility

@strengejacke
Copy link
Author

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
Copy link
Contributor

timtmok commented Jul 4, 2024

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
Copy link
Contributor

seeM commented Jul 5, 2024

Sort of requested in #3884.

@kylebutts
Copy link
Contributor

kylebutts commented Jul 6, 2024

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
Copy link
Contributor

nstrayer commented Jul 29, 2024

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 strengejacke changed the title Possibility to open plots in a browser to adjust scaling Possibility to adjust plot scaling (maybe by opening plots in a browser) Aug 1, 2024
@strengejacke
Copy link
Author

strengejacke commented Aug 1, 2024

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:

image

@strengejacke
Copy link
Author

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
Copy link

#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
Copy link
Contributor

timtmok commented Oct 21, 2024

#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 #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
Copy link

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: plots Issues related to Plots category. enhancement New feature or request support theme: app builder
Projects
None yet
Development

No branches or pull requests

8 participants