Plots

In this section, the following type of plots are being discussed:

Plots can be created with plot builder 1 in JGR 2. 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.

Code created using plot builder can be copied into a script file for convenience. 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’s 3 first data set; load the dataset and create a plot with the following commands:

ggplot() + geom_point(aes(x = X1,y = Y1),data=anscombe.quartet) + geom_smooth(aes(x = X1,y = Y1),data=anscombe.quartet,method = ‘lm’) + theme_bw() +ggtitle(label = ‘Anscombe\’s First Data Set’) + xlab(label = ‘X1 [cm]’) + ylab(label = ‘Y1 [cm]’)

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() + geom_point(aes(x = X1,y = Y1),data=anscombe.quartet) + geom_smooth(aes(x = X1,y = Y1),data=anscombe.quartet,method = ‘lm’) + theme_bw() +ggtitle(label = ‘Anscombe\’s First Data Set’) + xlab(label = ‘X1 [cm]’) + ylab(label = ‘Y1 [cm]’)

dev.off()

To create a jpg file:

jpeg(‘AnscombePlot.jpg’,quality=100,width=960,height=960,res=200)

ggplot() + geom_point(aes(x = X1,y = Y1),data=anscombe.quartet) + geom_smooth(aes(x = X1,y = Y1),data=anscombe.quartet,method = ‘lm’) + theme_bw() +ggtitle(label = ‘Anscombe\’s First Data Set’) + xlab(label = ‘X1 [cm]’) + ylab(label = ‘Y1 [cm]’)

dev.off()

There are similar commands for different graphical formats. For bitmap:

??png

and for scalable vector graphics:

??svg

1.
Wickham H, Chang W. ggplot2: Create Elegant Data Visualisations Using the Grammar of Graphics [Internet]. Springer New York; 2016. Available from: http://cran.r-project.org/package=ggplot2
1.
Fellows I. Deducer: A data analysis GUI for R. Journal of Statistical Software. 2012;49(8):1–15.
1.
Anscombe F. Graphs in statistical analysis. The American Statistician. 1973;27(1):17–21.