R Programming Notes – Unit V
Advanced Graphics
Plotting regions and margins
In R, a plot (graphic window) consist of following three regions:
Plot region : This is the region where actual plot appears. R uses the coordinate system to
draw the graphics.
Figure region (figure margin - mar) : This region consists the axes, labels, and title of a graph.
We can retrieve or set the figure region by using the “mar” parameter.
Outer region (outer margin - oma) : This is the outermost region which is not included by
default. This can be set by using the “oma” parameter.
KLS GCC BCA SEM V Page 1
R Programming Notes – Unit V
Point-and-Click Coordinate Interaction
The locator() function in R is used for interactive input of a set of graphic coordinates.
Explanation of the following R code snippet to understand the usage of locator() function:
1. A simple plot is first drawn using plot(1) function.
2. Then, run the locator() function. When locator function is active, the R allows to randomly
click on plot region.
KLS GCC BCA SEM V Page 2
R Programming Notes – Unit V
3. Once completed, click “Finish”. This allows to store the clicked co-ordinates into a vector
points.
4. Use print() function to prints all the clicked co-ordinates on the console.
Specialized Text and Label Notation
The R graphics allows to add following in the plot region:
customize font
o three font family (sans, serif, mono) are supported
o four format (normal, bold, italic, bold and italic) can be applied
Greek symbols
math expressions
KLS GCC BCA SEM V Page 3
R Programming Notes – Unit V
R uses the expression() function to add customized text and labels on the plot region. The following
code snippet demonstrates the usage expression() function:
Defining Colors
In R, colors can be defined and used in various following methods:
Color names :
> my_color <- “red”
Hexadecimal color codes :
> my_color <- “#FF0000”
RGB values :
> my_color <- rgb(1,0,0)
Color Palettes
KLS GCC BCA SEM V Page 4
R Programming Notes – Unit V
3D Scatterplots
KLS GCC BCA SEM V Page 5