1. proj.txt
#install.packages("xlsx", dependencies=TRUE)
#install.packages("lubridate", dependencies=TRUE)
#install.packages("zoo")
library(xlsx)
library(lubridate)
library(zoo)
# 1a.
strikes = read.xlsx("proj01_strikes.xlsx", sheetName="Labour",
as.data.frame=TRUE,header=TRUE)
# calculate strikes by year by locations
# This is to make one plot with all four Locations on the time plot in different
colors.
# Also for dynamic bubble graph and stacked up bar graph.
year=rep(c("2011/12/31","2012/12/31","2013/12/31","2014/12/31", "2015/02/28"),4)
locations=rep(c("Beijing","Chongqing","Guangdong","Shanghai"),each=5)
num_strikes=numeric(length(year))
for (i in 1:length(year))
{
num_strikes[i]=sum(strikes$Strikes[which(year(strikes$Date)==year(year[i])
& (strikes$Locations==locations[i]))])
}
labour=data.frame(year, locations, num_strikes)
write.csv(labour, "labour.csv",row.names=FALSE )
# create another data set for individual bar graph and cluster bar graph
Year=c("2011/12/31","2012/12/31","2013/12/31","2014/12/31", "2015/02/28")
Beijing=num_strikes[1:5]
Chongqing=num_strikes[6:10]
Guangdong=num_strikes[11:15]
Shanghai=num_strikes[16:20]
labour.alt=data.frame(Year,Beijing,Chongqing,Guangdong,Shanghai)
write.csv(labour.alt, "labour.alt.csv",row.names=FALSE)
#2
#install.packages("googleVis")
library(googleVis)
labour=read.csv("labour.csv",header=TRUE,sep=",")
# create another data set for dynamic bubble graph using google Chart Tools
Year = year(labour$year)
locations=labour$locations
num_strikes=labour$num_strikes
labour.g=data.frame(locations, Year, num_strikes)
M1 <- gvisMotionChart(labour.g, idvar="locations", timevar="Year",
sizevar="num_strikes")
plot(M1)
Page 1