Graphics Programs Reference
In-Depth Information
This is assuming you've changed your working directory accordingly. For
more options and instructions on how to load data using the read.csv()
function, type the following in the R console:
?read.csv
Moving on, now that the data is stored in the posts variable , enter the fol-
lowing line to see the first five rows of the data.
posts[1:5,]
You can also
install packages
in R through the
user interface. Go
to Packages &
Data ➪ Package
Installer. Click Get
List, and then find
the package of
interest. Double-
click to install.
You should see four columns that correspond to the original CSV file, with
id , views , comments , and category . Now that the data is loaded in R, make
use of the Portfolio package. Try loading it with the following:
library(portfolio)
Get an error? You probably need to install the package before you begin:
install.packages(“portfolio”)
You should load the package now. Go ahead and do that. Loaded with no
errors? Okay, good, now go to the next step.
The Portfolio package does the hard work with a function called map.market() .
The function takes several arguments, but you use only five of them.
map.market(id=data$id, area=posts$views, group=posts$category,
color=posts$comments, main=”FlowingData Map”)
The id is the column that indicates a unique point, and you tell R to use
views to decide the areas of the rectangles in the treemap, the categories
to form groups, and the number of comments in a post to decide color.
Finally, enter FlowingData Map as the main title. Press enter on your key-
board to get a treemap, as shown in Figure 5-18.
It's still kind of rough around the edges, but the base and hierarchy is set
up, which is the hard part. Just like you specified, rectangles, each of which
represent a post, are sized by the number of page views and sorted by
category. Brighter shades of green indicate posts that received more com-
ments; posts with a lot of views don't necessarily get the most comments.
You can save the image as a PDF in R and then open the file in Illustrator.
All regular edit options apply. You can change stroke and fill colors, fonts,
remove anything extraneous, and add comments if you like.
Search WWH ::




Custom Search