Book Image

R Data Visualization Cookbook

Book Image

R Data Visualization Cookbook

Overview of this book

Table of Contents (17 chapters)
R Data Visualization Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Constructing a tree map in R


Tree maps are basically rectangles placed adjacent to each other. The size of each rectangle is directly proportional to the data being used in the visualization. Tree maps have been used to plot the most watched news on the web by newsmap.jp. They have also been applied in financial websites such as smart money to visualize financial market movements. In this recipe, we will implement a tree map using the googleVis package.

Getting ready

We would require to install and load the googleVis package for the purpose of the visualization.

How to do it…

In order to implement a tree map, we would first install and load the googleVis library in the R session and import the data in the R session:

install.packages("googleVis")
library(googleVis)

We import the data using the read.csv() function and store the data as a data frame shk:

shk = read.csv("shrink.csv", header = TRUE, sep =",")

The following code creates a row and adds this to the data; this is necessary to make the code...