Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can i change the size of a png file with R

Tags:

r

I am plotting png files and getting a small picture.

Do you know some simple code that can change size of a png plot?

(my plots are too high and too "slim".

In addition is there a way to change resolution of the plot ?

thanks yigeal

like image 784
Yigael Satanower Avatar asked May 31 '11 15:05

Yigael Satanower


People also ask

How do I plot a PNG in R?

To add a picture to a plot in base R, we first need to read the picture in the appropriate format and then rasterImage function can be used. The most commonly used format for picture in R is PNG. A picture in PNG format can be added to a plot by supplying the values in the plot where we want to add the picture.


1 Answers

?png

png(filename = "Rplot%03d.png", width = 480, height = 480,
    units = "px", pointsize = 12, bg = "white", res = NA,
    restoreConsole = TRUE)

Change width and height in pixels, set res in dpi, default is 72 for larger plots I generally use something around 120. You'll have to play with it to get the font to look how you want it.

Example:

png()
plot(rnorm(100))
dev.off()
like image 166
Brandon Bertelsen Avatar answered Nov 03 '22 23:11

Brandon Bertelsen