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:

1.png

Clicking install to download and install the package:

2.png

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

library(ggplot2)
3.png

Run the line of script to console:

4.png

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():

plot(FDX$Median_4,FDX$Dependent)
5.png

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:

qplot(FDX$Median_4,FDX$Dependent)
6.png

Run the line of script to console:

7.png

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.