Print plot to file
Save current open screen figure as pdf file
Save current open screen figure as pdf file
# create plot example
x=c(1,2,3,4,5)
y=c(5,2,3,4,1)
plot(x,y)
# save plot as PDF file, size 6 × 6 inch
dev.copy(pdf, 'myfigure.pdf', width = 6, height = 6)
dev.off()
Print figure to PDF / PNG file (within a R-script)
Print figure to PDF / PNG file (within a R-script)
1) Define .pdf or .png output file-name
1) Define .pdf or .png output file-name
# define PDF file for writing
pdf(file = 'myfigure.pdf')
# define PNG file for writing
png(file = 'myfigure.png')
2) Run the plotting commands
2) Run the plotting commands
# Example: boxplot (not visible on screen, draw goes directly into pdf / png file)
x1=mydata$height
x2=mydata$width
boxplot(x1, x2, names=c("Height", "Width"), boxwex=0.4)
2) Save pdf / png output file
2) Save pdf / png output file
dev.off()