2) Creating a Scatter Plot for Closer Inspection with ggplot2.

This Blog entry is from the Linear Regression section in Learn R.

The scatter plot matrix created beforehand is an extremely useful and informative tool, if lacking beauty.  A package that cannot escape mention for the creation of graphics in R is ggplot2, which is a powerful and flexible graphics package for creating charts and visualisations every bit as beautiful as that which could be found in Excel. 

Start by installing the ggplot package using RStudio and as described in procedure 9:


Clicking install to download and install the package:


Once the packages has been downloaded and installed, reference the package using the library() function and its name ggplot2:


Run the line of script to console:


In this example a scatter plot will be created with the Dependent Vector on the y Axis and the Median_4 on the x axis, and initially using just the built in function plot():


The signature of the plot() function is effortless and it is a fantastic extensions to perform quick and exploratory data analysis,  although it may not be visually impressive enough for the purposes of presentations.  qplot() is a function in the ggplot2 package and achieves much the same,  just visually more striking:


Run the line of script to console:


The package ggplot2 provides a plethora of functions that will create rich and visually impressive graphics, from the being able to manipulate colours to correctly titling a plot with the intention of creating graphics fit for publishing. 

The ggplot functionality will be steadily introduced in subsequent Blog entries although creating visually striking charts for publication is outside the scope of this course.

11) List all Functions in a Package.

This Blog entry is from the Getting Started in R section in Learn R.

Once a package is loaded, beyond using the help, an understanding of all the functions available to the package can be obtained.   Although a script active, console passive approach is advocated this Blog entry is one of the few occasions where it is more appropriate to use the console directly rather than clutter up the script.

Click on the console window in the bottom left hand corner of RStudio:


Type directly into the console:


Press the Enter key to execute the script:


A list of all functions in the package is returned.

10) Load Packages using Script.

This Blog entry is from the Getting Started in R section in Learn R.

While the toggle function is a useful feature of RStudio,  the intention is to maintain a script Active, Console Passive approach, henceforth it is important to ensure that the librarby() function call, to be streamed to the console is moved to the head of the script and that the detach() function is moved to the base of the script.

Start by navigating to the very top of the script and create a new line in the script editor. Navigate to the start of the first line and press the enter key:


Invoking the library() function,  type:


Intelisense will look through the search path and suggest some packages,  and this can also be auto-completed to ggplot2.  Upon completion of the line,  run the script line to the console:


The ggplot library is now loaded as the first line of the script. 

9) Load and Unload Packages in RStudio.

This Blog entry is from the Getting Started in R section in Learn R.

When a package is installed it is not by default available for use, to save memory and resources.  Loading a package in RStudio is an extremely simple toggle process which will send the command to console to load a specific package on select,  unload on deselect.

Loading a package uses the library() function, invoked before a script is run.

Navigate to the packages pane in the bottom right hand corner of the RStudio, clicking on the tab if necessary.


Note the package that was installed previously,  ggplot2, and the check box to the left hand side of the package name.  To load the package simply select the textbox via a click of the mouse:


On selection of the checkbox the library() function, complete with the required parameters, will be processed in the console.  It can also be observed that the location of the package has been specified in this function call,  although that is not strictly necessary.

To unload the package,  deselect the checkbox in the packages pane next to ggplot2:


On deselection of the checkbox the detatch() function is sent to the console for the package (notice the string will match the return of the search() function).

8) Review Help and Documentation.

This Blog entry is from the Getting Started in R section in Learn R.

In the packages pane a list of all packages installed has been presented. Having followed previous Blog entries we know that ggplot2 is now installed.  It is customary for packages to carry good documentation,  which can be accessed by clicking on the hyperlink overlaying the package name:


Clicking on the link immediate navigation to the packages documentation takes place:


This feature provides a more intuitive means to navigate to documentation for functions. In this example,  scroll down and clock on the function link autoplot:


It can be seen that the documentation is displayed, navigating away from the index.