This time, as you expected, I am going to generate a one simple graph using R command. R provides diverse libraries relating visualization but this time I am going to use a plot function which is very simple.
I am going to use a file which is generated from last tutorial.
This file contains 4 columns(name,team,position,age) and 486 rows. but my interested column is "Age" column.
First, I should read data file in the R command prompt.
Once file data is stored in the any variable, you can take "Age" column and visualize it.
Let's try. Check the file name and location, and then just glance over a file contents. As you can see below there is no head information so be careful the read option when you read file contents
[hadoop08:37:06@NBA]$tail -10 NBAFILE_Through_web.txt
Jeff Withey Nor C 23
Nate Wolters Mil PG 22
Brandan Wright Dal C 26
Chris Wright Mil SF 25
Dorell Wright Por SF 28
Tony Wroten Phi SG 20
Nick Young Lal SG 28
Thaddeus Young Phi PF 25
Cody Zeller Cha C 21
Tyler Zeller Cle C 24
And then go into the R command prompt and read the file with read package util. Just a little bit endeavor is required for convenience. If you are not familiar with plot function then read description with a simple command.
>?plot
> nbafile = read.csv(file="/home/hadoop/python2.7/NBA/NBAFILE_Through_web.txt" , header=FALSE, sep="\t")
> names(nbafile) = c('NAME','TEAM','POSITION','AGE')
> plot(nbafile$AGE, xlab="player", ylab="Age" ,col="red", xlim=c(1,500), ylim=c(15,40), type="p", main="Individual Age")
Can you distinguish which graph is generated by R command ?
Answer is right one. It is easy because the left one is the exact same one we made in previous tutorial.

No comments:
Post a Comment