Chapter 9 IT

9.1 R

9.1.1 Install Packages

  • Install packages from sources
# donwload the source and install the package using the following command
install.packages("C:/Users/linhu/Hui/R/ggcounty",repos=NULL, type="source")
  • Install packages from github
library(devtools)

9.1.2 Read .R and .RDA files from a folder

  • ‘.R’ files
setwd("path")
file.sources=list.files(pattern="*.R")
sapply(file.sources,source,.GlobalEnv)
  • ‘.RDA’ files
data.sources=list.files(pattern="*.RDA")
sapply(file.sources,load,.GlobalEnv)

9.1.3 Visualization

9.1.3.1 recharts

  • recharts from Yihui
# install.packages('recharts',
#                 repos = c("http://yihui.name/xtran","http://cran.rstudio.com"),
#                 type="source")
library(recharts)
echart(iris, ~Sepal.Length, ~Sepal.Width)
echart(iris, ~Sepal.Length, ~Sepal.Width, series= ~Species)
  • recharts from Taiyun
# install.packages("C:/Users/linhu/Hui/R/recharts",repos=NULL, type="source")
library(recharts)
library(jsonlite)
library(lubridate)
library(dplyr)
library(tidyr)
units<-c(12,32,43,45,54,21,35,67)
time<-rep(c("2015-10-1","2015-11-1","2015-12-1","2016-2-1"),c(2,2,2,2))
time<-ymd(time)
source<-rep(c("Var1","Var2"),4)
dat<-data.frame(units,time,source)
sdat<-dat%>%spread(source,units)
row.names(sdat)<-sdat$time
sdat<-select(sdat,-time)
plot(eBar(sdat))

9.1.3.2 rCharts

library(rCharts)
hair_eye=as.data.frame(HairEyeColor)
rPlot(Freq~Hair | Eye, color='Eye', data=hair_eye, type="bar")
hair_eye_male<-subset(as.data.frame(HairEyeColor),Sex=="Male")
n1<-nPlot(Freq~ Hair, group="Eye",data=hair_eye_male,type="multiBarChart")
n1

9.1.3.3 ggcounty

ggplot2 - Famous package for making beautiful graphics. It lets you use the grammar of graphics to build layered, customizable plots

ggvis - Interactive, web based graphics built with the grammar of graphics

rgl - Interactive 3D visualizations

htmlwidgets - A fast way to build interactive (javascript based) visualizations with R. Packages that implement htmlwidgets include: - leaflet (maps) - dygraphs (time series) - DT (table) - diagrammerR (diagrams) - netword3D (network graphs) - threeJS (3D scatterplots and globes)

googleVis - Let you use Google Chart tools to visualize data in R. Google Chart tools used to be called Gapminder, the graphing software Hans Rosling made famous in his TED talk.

9.1.4 Manipulate data

9.1.4.1 lubridat

Tools that make working with dates and times easier.

dplyr - Essential shortcuts for subsetting, summarizing, rearranging and joining together data sets. dplyr is a go to package for fast data manipulation

tidyr - Tools for changing the layout of your data sets. Using the gather and spread functions to convert your data into the tidy format