Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resize and save plots in png format?

Tags:

I would like to plot the results from a quantile regression, but am not able to:

  1. control the dimensions/size of the plots and
  2. save the plots as png.

Here is my code:

require(quantreg) data(engel) attach(engel) xx <- income - mean(income) zz <- c(120, diff(income)) fit1 <- summary(rq(foodexp~xx+zz, tau=2:98/100)) 

Then:

png('res.png') plot(fit1, mfrow=c(1,2)) 

Only the zz plot is saved to the res.png file.. Is there any way I can save the plots in separate files (two and one)? and how do I control the width/height of the plots? I like all the individual plots to have width=height (square) when i save them to the .png file?

like image 708
quantplot Avatar asked Jun 03 '11 12:06

quantplot


People also ask

How do I resize a png in R?

To resize the image, use image_scale() function. where value is either relative to parent object or fixed size values. Value = 100% or 500 or 200%, etc.

How do I change the resolution of a plot in R?

In base R, we can save a plot as a png and pass the resolution in the same stage. The procedure to do this is creating the png image with resolution with res argument then creating the plot and using dev. off() to create the file.

How do you save a scatter plot in R?

Under Windows, right click inside the graph window, and choose either "Save as metafile ..." or "Save as postscript ..." If using Word, make sure to save as a metafile.


1 Answers

You can control the image dimensions by png argument.

png("image.png", width = 800, height = 600) plot(...) dev.off() 

To "finish" the image, use dev.off.

like image 200
Roman Luštrik Avatar answered Sep 19 '22 16:09

Roman Luštrik