Tuesday, October 18, 2016

Introduction to Open Source R for Visualization


In this exercise I downloaded and installed the R language and R Studio in order to perform some basic analysis and visualization on a set of nine numbers. To get started I installed R base version 3.3.1 downloaded from https://cran.rstudio.com/bin/windows/base/ and then R Studio version 0.99.903, as downloaded from www.rstudio.com/products/rstudio/download.

To assign values to variables in R the symbol ‘=’ or the combo of symbols ‘<-‘ can be used. For this exercise the values being assigned are 10, 20, 30, 40, 50, 60, 70, 80, and 81. This set of values can be passed to our variable holding the values by using the R function c(). This function c() is a generic function that combines or concatenates its arguments, so by assigning c(10, 20, 30, 40, 50, 60, 70, 80, 81) to our variable the concatenated series of numbers in an array.


To experiment with R through R Studio instructions can be entered directly into the Console:

We can also look in the Environment window of R Studio to see that the numbers are assigned to variable “values” and that these numbers are stored as type numeric in an array indexed 1 to 9:


R makes it dig right into analysis and visualization; we can create a pie chart simply by calling the function pie() with our variable, values:



The labels in this pie chart are the index values of the array and this is not easy to read or to understand. We can create our own labels by calling the function names() with our variable as the argument and pass names() the labels to assign. For simplicity we will assign the values to be the labels and then call pie(values) again for a new plot:



We can also plot the variable “values” as a bar chart by calling the function barplot():



We can now take these instructions are store them in an R script:






No comments:

Post a Comment