Plots can be created with the ggplot package1. The plot can be subsequently saved in the desired format. As described, scalable vector graphics are advised, but ultimately the choice of format depends on its subsequent use / journal requirements.
Rather that creating the plots and saving them it may be more convenient to save the plot directly in the desired format. For example to create a plot of Anscombe’s2 first data set; load the dataset and create a plot with the following commands:
ggplot(data=anscombe.quartet, aes(x = X1,y = Y1)) +
geom_point() +
geom_smooth(method = 'lm') +
ggtitle(label = 'Anscombe\'s First Data Set') + xlab(label = 'X1 [cm]') +
ylab(label = 'Y1 [cm]') +
theme_bw()
The plot can subsequently be saved in the appropriate format.
To save directly as a PDF file in the default directory of R:
pdf('AnscombePlot.pdf')
ggplot(data=anscombe.quartet, aes(x = X1,y = Y1)) +
geom_point() +
geom_smooth(method = 'lm') +
ggtitle(label = 'Anscombe\'s First Data Set') + xlab(label = 'X1 [cm]') +
ylab(label = 'Y1 [cm]') +
theme_bw()
dev.off()
To create a jpg file:
jpeg('AnscombePlot.jpg',quality=100,width=960,height=960,res=200)
ggplot(data=anscombe.quartet, aes(x = X1,y = Y1)) +
geom_point() +
geom_smooth(method = 'lm') +
ggtitle(label = 'Anscombe\'s First Data Set') + xlab(label = 'X1 [cm]') +
ylab(label = 'Y1 [cm]') +
theme_bw()
dev.off()
There are similar commands for different graphical formats. For bitmap:
??png
and for scalable vector graphics:
??svg