[R] Save a graph file use jpeg(file=file)

Sorkin, John j@ork|n @end|ng |rom @om@um@ry|@nd@edu
Thu Jan 6 02:23:34 CET 2022


Ducan,

As always, you are very giving of your time to help R users. Thank you!

scatter3d is from the car package.

As I understand snapshot3d, it takes a screen shot and saves the resultant file. This implies that the resultant file will be 72 DPI. I need to get a higher resolution image, at least 300 DPI. Do you have any suggestions?

Thanks as always.

John

________________________________________
From: Duncan Murdoch <murdoch.duncan using gmail.com>
Sent: Wednesday, January 5, 2022 2:58 PM
To: Sorkin, John; r-help using r-project.org (r-help using r-project.org)
Subject: Re: [R] Save a graph file use jpeg(file=file)

On 05/01/2022 2:45 p.m., Sorkin, John wrote:
> I am trying to create a 3-D graph (using scatter3d) and save the graph to a file so I can insert the graph into a manuscript. I am able to create the graph. When I run the code below an RGL window opens that has the graph. The file is saved to disk after dev.odd() runs. Unfortunately, when I open the saved file, all I see is a white window. Can someone tell me how to have the file so I can subsequently read and place the file in a paper? The problem occurs regardless of the format in which I try to save the file, e.g. png, tiff.
>
>
> x <- 1:10
> y <- 2:11
> z <- y+rnorm(10)
> ForGraph<-data.frame(x=x,y=y,z=z)
> ForGraph
>
> gpathj <- file.path("C:","LAL","test.jpeg")
> gpathj
> jpeg(file = gpathj)
> par(mai = c(0.5, 0.5, 0.5, 0.5))
> scatter3d(z=ForGraph$x,
>            y=ForGraph$y,
>            x=ForGraph$z,
>            surface=FALSE,grid=TRUE,sphere.size=4
>            ,xlab="Categories",ylab="ScoreRange",
>            zlab="VTE Rate (%)",axis.ticks=TRUE)
> dev.off()
>
>

You didn't say what package you found scatter3d in, but you did say it
opens an rgl window.  rgl doesn't use R graphics devices, so jpeg() and
the like don't work.

To save an rgl image, you use the rgl::snapshot3d() function.  It only
has support for saving to PNG format.

If you are writing your manuscript in R Markdown or knitr Rnw, there are
ways to have the file included automatically.  There have been methods
to use with Sweave as well, but those aren't being maintained:  people
should use knitr instead.

Duncan Murdoch

	[[alternative HTML version deleted]]



More information about the R-help mailing list