Hello everybody! This is the first part of an exciting data visualization series r exercises.com is going to provide you.
Data visualization involves the creation and study of the visual representation of data. The increasing amounts of data created by Internet activity make the “data visualization” tool totally necessary for data scientists.
One of the best packages that R language provides for this purpose is googleVis and guess what, we are going to see its amazing features together. In this first part we are going to see basic stuff of three useful types of charts (Line Chart, Bar Chart and Column Chart) before “digging deeper” in the next parts.
NOTE: The charts are created locally by your browser. In case they are not displayed at once press F5 to reload the page.
Read the examples below to understand the logic of what we are going to do and then test yous skills with the exercise set we prepared for you. Lets begin!
Answers to the exercises are available here.
Install the Package.
Install and load the package googleVis.
Create a data frame
First of all let’s create an experimental
data.frame to use for all our plots. This is an example:
dfr=data.frame(name=c("GRE", "ARG", "BRA"),
Create a data frame named “df”. Give as variables the “Pts” (Points) and “Rbs” (Rebounds) of three NBA players. Names and values are up to you.
To produce a Line Chart you can use:
LineC <- gvisLineChart(df)
list named “LineC” and pass to it the “df” data frame you just created as a line chart. HINT: Use
Plot the line chart. HINT: Use
Line chart with two axis
Below there is an example of this type of Line Chart:
LineC2 <- gvisLineChart(df, "name", c("val1","val2"),
As you can see you create a
list (options) that corresponds values 1 & 2 in the two axes respectively.
Create a single axis Line chart that displays only the “Pts” of the “df” data frame.
Now create a two axis line chart that displays both “Pts” and “Rbs” of the “df” data frame. HINT: Use
It is quite simple to create a bar chart with googleVis with:
BarC <- gvisBarChart(df)
list named “BarC” and pass to it the “df” data frame you just created as a bar chart. HINT: Use
Plot the bar chart. HINT: Use
Column charts could be considered as vertical bar charts and are quite simple to be created too.
ColumnC <- gvisColumnChart(df)
list named “ColumnC” and pass to it the “df” data frame you just created as a column chart. HINT: Use
Plot the column chart. HINT: Use