View saved plots in RStudio on RAP?

I'd like to make a plot in RStudio , save it + view it. This is so that I can iterate on aspects of plotting (e.g. size of elements). I don't want to work just in the Plots pane in RStudio, as the size of the canvas when saving files is an important element of how the final plot looks.   Currently, I'm finding I need to upload then download the files to view, which is very slow + also risks accidentally downloading data unintentionally (as you can't view the plot to check it contains only the info you think). Is there a better way round this?     For additional context I'm saving with: svg("my_file.svg") my_plot dev.off() ... though I've also tried with png without success.

Comments

3 comments

  • Comment author
    Ondrej Klempir DNAnexus Team

    Why you need to upload and then download the files?

     

    I am wondering whether the following is something you are looking for:

     

    Screenshot 2022-10-14 at 15.14.32require("ggplot2")

    #some sample data

    head(diamonds) 

    #to see actually what will be plotted and compare 

    qplot(clarity, data=diamonds, fill=cut, geom="bar")

    #save the plot in a variable image to be able to export to svg

    image=qplot(clarity, data=diamonds, fill=cut, geom="bar")

    #This actually save the plot in a image

    ggsave(file="test.png", plot=image, width=10, height=8, dpi = 300, units = "in", device='png')

     

    Screenshot 2022-10-14 at 15.14.44Clicking on test.png will open a new window with a large size image view.

     

    Screenshot 2022-10-14 at 15.14.59

    0
  • Comment author
    Ondrej Klempir DNAnexus Team

    Similarly for the exported svg file format, I just changed the "png" in path to "svg" and svg is loaded:

     

    Screenshot 2022-10-14 at 15.21.53

    0
  • Thanks @Ondrej Klempir?! That's now working. Turns out I'd managed to save an empty png file, which was why I couldn't get that to work :) In case it's useful to others, for svg RStudio by default tries to open as if it were a text file. But using the path as you did works!

    0

Please sign in to leave a comment.