I was fooling around with including a p-value and R2 value on a plot I was putting together, and found myself quickly descending into the world of R graphics esoterica. I wanted to be able to include the values on the fly using values extracted from a linear model summary object, and I wanted to use the proper italics and superscripts for the text. The desired output is shown below. What follows is how I finally generated the plot.
* You are viewing Posts Tagged ‘superscript’
Below is a walk-through of some of the basics of customizing plots in R. These are all based on the graphics package that comes in the base installation of R.
Let’s start by making a basic plot in R. In the code snippets below, green text behind a # sign is considered comments by R, so everything after a # sign on a line will be ignored by R. We’ll call the plot command and supply it with two vectors of numbers representing the x and y values:
plot(c(1,2,3,4,5,6),c(4,3,6,2,1,1)) #x and y data for our example plot
which produces this plot: