I have a huge scatter plot matrix to generate and save into a zoom-able image. I takes a bunch of hours to draw and then I got some errors like:
"Server Error Unabe to establish connection with R session".
Any ideas? The problem is obviously memory, but there must be a way to get around this.
I've managed to save the file as a pdf format of 28.7 MB, it takes a lot of time to display and makes inkscape crash. I know that people who generate fractals are able to make images of infinite resolution without consuming a lot of memory since the image is generate as u zoom into it. Problem is fractals are self similar and scatterplots are not, so I'm not sure if there's a smart way to get around this issue.
A possible way to get around this "information overload" is to plot variables in pairs using qplot() and then save the file using ggsave(), for example in bmp on jpeg files.
Related
I am trying to use the default plot() function in R to try and plot a shapefile that is about 100MB, using RStudio. When I try and plot the shapefile, the command doesn't finish executing for around 5 minutes, and when it finally does, the plotting window remains blank. When I execute the same process exactly in VS Code, the plot appears almost instantly, as expected.
I have tried uninstalling and reinstalling RStudio with no success.
I can't speak for what VStudio does, but I can guarantee that plotting 100MB worth of data points is useless (unless the final plot is going to be maybe 6 by 10 meters in size).
First thing: can you load the source file into R at all? One would hope so since that's not a grossly huge data blob. Then use your choice of reduction algorithms to get a reasonable number of points to plot, e.g. 800 by 1600, which is all a monitor can display anyway.
Next try plotting a small subset to verify the data are in a valid form, etc.
Then consider reducing the data by collapsing maybe each 10x10 region to a single average value, or by using ggplot2:geom_hex .
I was wondering if there is a way to save surface plots in IDL in a way that is convenient to reopen them. As far as I am aware there are only two ways of doing this:
The first way is to save your surface plot as an image e.g. png. The trouble with this is that the viewing angle is fixed and you can no longer drag with the mouse to rotate the surface plot.
The second way is to save the code which generates the plot. Trouble with this is the code often generates loads of plots which are usually just saved as images.
I would like something you can open easily and which opens the surface plot as though you had just run the code to generate it. So that you are free to rotate it by dragging the mouse.
Does this exist?
I only have IDL version 8.3.
If you 'Generate code/save data' (either via the toolbar at the bottom of the window or via the generateCode method with the SAVEDATA keyword), you get a .sav file that contains your plot. Either use the code generated to restore it, or use the generated code as an example to write your own.
Hello everybody out there using R,
When putting multiple plots with thousands of data points into a single PDF file, this file can get huge and take a long time to open.
The following post describes exactly the same problem in Matplotlib, as well as a nice fix for it:
Matplotlib: multipage PDF with rasterized plots
Particularly nice about it is, that it only rasterizes the points without rasterizing the labels.
http://www.astrobetter.com/blog/2014/01/17/slim-down-your-bloated-graphics/ contains a nice example of it.
I am now looking for a similar solution in R.
So I have to save a pdf plot with a lot of points in it. That is not a problem. The problem is that when I open it. It takes forever to plot all those points. How can I save this pdf in such a way that it doesn't have to draw point by point when someone opens it. I'm OK if the quality of the picture goes down a bit.
Here's a sample. I don't think this would crash your computer but be careful with the parameter length if you have an old machine. I am using many more points than that in my real problem by the way.
pdf("lots of points.pdf")
x <- seq(0,100, length = 100000)
y <- 0.00001 * x
plot(x, y)
dev.off()
I had a similar problem and there is a sound solution. The drawback is that this solution is not generic and does not involve programming (always bad).
For draft purposes, png or any other graphic format may be sufficient, but for presentation purposes this is often not the case. So the way to go is to combine vector graphics for fonts, axis etc and bitmap for your zillions of points:
1) save as pdf (huge and nasty)
2) load into illustrator or likewise ( must have layers )
3) separate points from all other stuff by dragging other stuff to new layer - save as A
4) delete other stuff and export points only as bitmap (png, jpg) and save as B
5) load B into A; scale and move B to exact overlap; delete vector points layer, and export as slender pdf.
done. takes you 30 minutes.
As said this has nothing to do with programming, but there is simply no way around the fact that as vector graphics each and every point (even those that are not visible, since covered by others) are single elements and its a pain handling pdfs with thousands of elements.
So there is need for postprocessing. I know ImageMagick can do alot, but AFAIK the above cant be done by an algorithm.
The only programming way to (partly) solve this is to eliminate those points that will not display because the are covered by others. But thats beyond me.
Only go this way if you really and desperately need extreme scalability, otherwise go with #Ben and #inform and use a bitmap --in whatever container you need it (png,pdf,bmp,jpg,tif, even eps).
I am making some graphs with R and I am coping them to Word. I was coping them as metafiles but Word doesn't seem to be able to cope with them. The other option in R to copy graphs is a bitmap, but when I use this the quality of the graphs in word is terrible.
I saw some answers about changing the resolution in this website but only if I saved the graphs which I would like to avoid. Is there a way of changing the resolution for copied graphs?
Thanks,
sbg
When the graphs are onscreen, they are drawn for a screen resolution (i.e. 72dpi). For print, you need to use at least 300dpi, or switch to a vector format. Word can import graphs in Windows Metafile (.wmf) format; but your other option is to save the plot using, e.g.,
png("my plot.png", res = 300)
plot(1:5)
dev.off()
This saves to disk, which you said you wanted to avoid, but you can always delete it again later (programatically even, with file.remove).
I'd also like to make the case that when you copy and paste, your work isn't as easily reproducible as when you use code. There is no trace of what you have done, and when your data changes, you need to go through the rigmarole of clicking again, rather than just executing your updated script.