                             width=600, height=350,#
                            zoomStartTime=as.Date("2006-04-01"),#
                            zoomEndTime=as.Date("2006-07-01")) #
                          )
plot(A3)
my.df
A3 <- gvisAnnotatedTimeLine(my.df, datevar="Date",#
                           numvar="Value", idvar="Device",#
                           titlevar="Title", annotationvar="Annotation",#
                           options=list(scaleColumns='[]',#
                            scaleType='allmaximized',#
                             width=600, height=350,#
                            zoomStartTime=as.Date("2008-01-04"),#
                            zoomEndTime=as.Date("2008-01-06")) #
                          )
plot(A3)
#
## Zoom into the time window, no Y-axis ticks#
A3 <- gvisAnnotatedTimeLine(my.df, datevar="Date",#
                           numvar="Value", idvar="Device",#
                           titlevar="Title", annotationvar="Annotation",#
                           options=list(scaleColumns='[]',#
                            scaleType='allmaximized',#
                             width=600, height=350,#
                            zoomStartTime=as.Date("2008-01-04"),#
                            zoomEndTime=as.Date("2008-01-05")) #
                          )
plot(A3)
## Zoom into the time window, no Y-axis ticks#
A3 <- gvisAnnotatedTimeLine(my.df, datevar="Date",#
                           numvar="Value", idvar="Device",#
                           titlevar="Title", annotationvar="Annotation",#
                           options=list(#
                             width=600, height=350,#
                            zoomStartTime=as.Date("2008-01-04"),#
                            zoomEndTime=as.Date("2008-01-05")) #
                          )
plot(A3)
## Create data as used by Google in their example#
 Date <- as.Date(paste("2008-1-", 1:6, sep=""))#
 Pencils <- c(3000, 14045, 5502, 75284, 41476, 333222)#
 Pencils.titles <-c(rep(NA,4), 'Bought Penciles', NA)#
 Pencils.annotation <-c(rep(NA,4), 'Bought 200k pencils', NA)#
 Pens <- c(40645, 20374, 50766, 14334, 66467, 39463)#
 Pens.titles <- c(rep(NA, 3), 'Out of stock', NA, NA)#
 Pens.annotation <- c(rep(NA, 3), 'Ran of stock on pens at 4pm', NA, NA)#
#
 original.df=data.frame(Date, Pencils, Pencils.titles,#
                        Pencils.annotation, Pens, Pens.titles,#
                        Pens.annotation)
 Date <- as.Date(paste("2008-1-", 1:6, sep=""))#
 Pencils <- c(3000, 14045, 5502, 75284, 41476, 333222)#
 Pencils.titles <-c(rep(NA,4), 'Bought Penciles', NA)#
 Pencils.annotation <-c(rep(NA,4), 'Bought 200k pencils', NA)#
 Pens <- c(40645, 20374, 50766, 14334, 66467, 39463)#
 Pens.titles <- c(rep(NA, 3), 'Out of stock', NA, NA)#
 Pens.annotation <- c(rep(NA, 3), 'Ran of stock on pens at 4pm', NA, NA)#
#
 original.df=data.frame(Date, Pencils, Pencils.titles,#
                        Pencils.annotation, Pens, Pens.titles,#
                        Pens.annotation)  #
#
#
 my.df <- reshape(original.df, idvar="Date", times=c("Pencils", "Pens"), #
                  timevar="Device",#
                  varying=list(c("Pencils", "Pens"),#
                               c("Pencils.titles", "Pens.titles"),#
                               c("Pencils.annotation", "Pens.annotation")), #
                   v.names=c("Value", "Title", "Annotation"),#
                   direction="long")
my.df
rownames(my.df)
rownames(my.df)=NULL
my.df
Exports
Export
library(googleVis)
Exports
my.df
Stock
Stock <- my.df
Stock
save(Stock, file="~/Dropbox/google-motion-charts-with-r/data/Stock.Rdata")
prompt(Stock, file="~/Dropbox/google-motion-charts-with-r/man/Stock.Rd")
 Date <- as.Date(paste("2008-1-", 1:6, sep=""))#
 Pencils <- c(3000, 14045, 5502, 75284, 41476, 333222)#
 Pencils.titles <-c(rep(NA,4), 'Bought Penciles', NA)#
 Pencils.annotation <-c(rep(NA,4), 'Bought 200k pencils', NA)#
 Pens <- c(40645, 20374, 50766, 14334, 66467, 39463)#
 Pens.titles <- c(rep(NA, 3), 'Out of stock', NA, NA)#
 Pens.annotation <- c(rep(NA, 3), 'Ran of stock on pens at 4pm', NA, NA)#
#
 original.df=data.frame(Date, Pencils, Pencils.titles,#
                        Pencils.annotation, Pens, Pens.titles,#
                        Pens.annotation)  #
#
#
 Stock <- reshape(original.df, idvar="Date", times=c("Pencils", "Pens"), #
                  timevar="Device",#
                  varying=list(c("Pencils", "Pens"),#
                               c("Pencils.titles", "Pens.titles"),#
                               c("Pencils.annotation", "Pens.annotation")), #
                   v.names=c("Value", "Title", "Annotation"),#
                   direction="long")
Stock
browseRsp()
?gvisTreeMap
demo(googleVis)
Exports
Fruits
plot(gvisAnnotatedTimeLine(Fruits, datevar="Data", numvar="Profit"))
plot(gvisAnnotatedTimeLine(Fruits, datevar="Date", numvar="Profit"))
plot(gvisAnnotatedTimeLine(Fruits, datevar="Date", numvar="Profit", idvar="Fruit"))
str(Stock)
library(XML)
install.packages('XML', repos='http://cran.r-projecy.org')
install.packages('XML', repos='http://cran.r-project.org')
library(XML)
?readHTMLTable
u = "http://en.wikipedia.org/wiki/World_population"#
 #
 tables = readHTMLTable(u)#
 names(tables)
w="http://www.londonstockexchange.com/exchange/prices-and-markets/stocks/summary/company-summary.html?fourWayKey=GB00B2988H17GBGBXSTMM"
tb=readHTMLTable(w)
names(w)
names(tb)
tb
tb[[5]]
names(tb)
tb[[10]]
f="http://www.londonstockexchange.com/exchange/prices/stocks/summary/fundamentals.html?fourWayKey=GB00B2988H17GBGBXSTMM"
fn=readHTMLTable(f)
fn
f2='http://www.londonstockexchange.com/exchange/prices-and-markets/stocks/exchange-insight/company-news.html?fourWayKey=GB00B2988H17GBGBXSTMM'
an=readHTMLTable(f2)
an
if (!require(XML)) install.packages('XML')#
library(XML)#
x = readHTMLTable('http://www.disastercenter.com/crime/iacrime.htm')#
## the 3rd element is what we want#
x = x[[3]]#
## names are in the first 2 rows#
nms = as.vector(apply(x[1:2, ], 2, paste, collapse = ''))#
## remove the first 2 rows because they are not data#
x = x[-(1:2), ]#
## assign the names to data#
names(x) = nms#
## then remove any characters which are not numbers (i.e. 0-9)#
x = sapply(x, function(xx) as.numeric(gsub('[^0-9]', '', xx)))
x
head(x)
install.packages('roxygen')
library(roxygen)
?roxygenize
?roxygen
roclet <- make.Rd.roclet('f')
roclet
roclet$parse('~/Desktop/Test.R')
library(googleVis)
Stock
data(Stock)
library(googleVis)
example(gvisAnnotatedTimeLine)
?gvisgvisAnnotatedTimeLine
?gvisAnnotatedTimeLine
data(Stock)#
Stock#
A1 <- gvisAnnotatedTimeLine(Stock, datevar="Date",#
                           numvar="Value", idvar="Device",#
                           titlevar="Title", annotationvar="Annotation",#
                           options=list(displayAnnotations=TRUE,#
                            width=600, height=350)#
                           )#
## Not run: #
plot(A1)#
#
## End(Not run)#
#
## Two Y-axis#
#
#
A2 <- gvisAnnotatedTimeLine(Stock, datevar="Date",#
                           numvar="Value", idvar="Device",#
                           titlevar="Title", annotationvar="Annotation",#
                           options=list(displayAnnotations=TRUE, #
                            width=600, height=350, scaleColumns='[0,1]',#
                            scaleType='allmaximized')#
                          )#
## Not run: #
plot(A2)#
#
## End(Not run)#
#
## Zoom into the time window, no Y-axis ticks#
A3 <- gvisAnnotatedTimeLine(Stock, datevar="Date",#
                           numvar="Value", idvar="Device",#
                           titlevar="Title", annotationvar="Annotation",#
                           options=list(#
                             width=600, height=350,#
                            zoomStartTime=as.Date("2008-01-04"),#
                            zoomEndTime=as.Date("2008-01-05")) #
                          )#
## Not run: #
plot(A3)#
#
## End(Not run)
?googleVis
library(XML)
fn="http://www.lloyds.com/The-Market/Tools-and-Resources/Resources/Statistics-Relating-to-Lloyds/Visualisation"
x=readHTMLTable(fn)
names(x)
x
readHTMLTable(fn)
fn="http://www.lloyds.com/The-Market/Tools-and-Resources/Resources/Statistics-Relating-to-Lloyds/Visualisation/index.html"
readHTMLTable(fn)
fn="http://www.lloyds.com/The-Market/Tools-and-Resources/Resources/Statistics-Relating-to-Lloyds/Visualisation/index.htm"
readHTMLTable(fn)
fn="http://www.lloyds.com/The-Market/Tools-and-Resources/Resources/Statistics-Relating-to-Lloyds/Visualisation/"
readHTMLTable(fn)
?gvisAnnotatedTimeLine
?browseRsp
browseRsp()
library(XML)
fn="http://investing.businessweek.com/research/stocks/financials/financials.asp?ticker=AAPL:US"
x=readHTMLTable(fn)
names(x)
x
x[[1]]
fn="http://investing.businessweek.com/research/stocks/earnings/earnings.asp?ticker=AAPL:US"
x=readHTMLTable(fn)
x
fn="http://investing.businessweek.com/research/stocks/earnings/earnings.asp?ticker=AML:UK"
x=readHTMLTable(fn)
fn="http://investing.businessweek.com/research/stocks/earnings/earnings.asp?ticker=AML:LN"
x=readHTMLTable(fn)
x
fn="http://investing.businessweek.com/research/stocks/snapshot/snapshot.asp?ticker=AML:LN"
x=readHTMLTable(fn)
x
fn="http://investing.businessweek.com/research/stocks/snapshot/snapshot_article.asp?ticker=AML:LN"
x=readHTMLTable(fn)
fn="http://investing.businessweek.com/research/stocks/financials/financials.asp?ticker=AML:LN"
x=readHTMLTable(fn)
x
fn="http://investing.businessweek.com/research/stocks/financials/ratios.asp?ticker=AML:LN"
x=readHTMLTable(fn)
x
fn="http://investing.businessweek.com/research/stocks/people/people.asp?ticker=AML:LN"
x=readHTMLTable(fn)
x
fn="http://investing.businessweek.com/research/stocks/people/people.asp?ticker=CGL:LN"
x=readHTMLTable(fn)
x
library(googleVis)
M=gvisMotionChart(Fruits, "Fruit", "Year")
M$html$chart
cat()M$html$chart)
cat(M$html$chart)
## googleVis demo#
#
pause <- function(){  #
  invisible(readline("\nPress <return> to continue: ")) #
}#
#
## For the demo a web browser with internet connection and Flash is required.#
## Further you need write access to the following directory#
system.file(file.path("rsp", "myAnalysis"), package="googleVis")#
#
## Motion Chart#
Motion=gvisMotionChart(Fruits, idvar="Fruit", timevar="Year")#
plot(Motion)#
pause()#
#
## Geo Map with coloured regions#
Geo=gvisGeoMap(Exports, locationvar="Country", numvar="Profit",#
                       options=list(height=350, dataMode='regions'))#
plot(Geo)#
pause()#
#
#
## Show Hurricane Andrew (1992) storm track with Geo Map#
AndrewGeo <- gvisGeoMap(Andrew, locationvar="LatLong", numvar="Speed_kt", #
      			 hovervar="Category", #
      		         options=list(height=350, region="US"))#
#
plot(AndrewGeo)#
pause()#
#
## Hurricane Andrew (1992) storm track with Google Maps#
AndrewMap <- gvisMap(Andrew, "LatLong" , "Tip", #
      	      options=list(showTip=TRUE, showLine=TRUE, enableScrollWheel=TRUE,#
		      mapType='terrain', useMapTypeControl=TRUE))#
plot(AndrewMap)#
pause()#
#
#
## Table. Click on the column header to sort the rows #
Table <- gvisTable(Exports, options=list(width=400, height=300))#
plot(Table)#
pause()#
#
## Table with embedded links#
PopTable <- gvisTable(Population, options=list(width=600, height=300, page='enable'))#
plot(PopTable)#
pause()#
#
## Tree Map. Left mouse-click to drill down, right mouse-click to move up a hierarchy#
Tree <- gvisTreeMap(Regions,  "Region", "Parent", "Val", "Fac", options=list(fontSize=16))#
plot(Tree)#
pause()#
#
## Annotated Time Line Chart#
AnnoTimeLine  <- gvisAnnotatedTimeLine(Stock, datevar="Date",#
                           numvar="Value", idvar="Device",#
                           titlevar="Title", annotationvar="Annotation",#
                           options=list(displayAnnotations=TRUE,#
                            width=600, height=350)#
                           )#
plot(AnnoTimeLine)#
pause()#
#
#
## Several charts on one page#
Page <- list(type="MotionGeoTableTree", #
			 chartid=format(Sys.time(), "MotionGeoTableTree-%Y-%m-%d-%H-%M-%S"), #
			 html=list(Header=Motion$html$header,#
			 		Chart1=Motion$html$chart,#
					Caption1=Motion$html$caption,#
					Chart2=Geo$html$chart,#
					Caption2=Geo$html$caption,#
					Chart3=Table$html$chart,#
					Caption3=Table$html$caption,#
					Chart4=Tree$html$chart,#
					Caption4=Tree$html$caption,#
                 			Chart4=AndrewMap$html$chart,#
					Caption4=AndrewMap$html$caption,#
                                        Chart5=AnnoTimeLine$html$chart,#
                                        Caption5=AnnoTimeLine$html$caption,               #
					Footer=Tree$html$footer)#
            )#
		#
#
class(Page) <- list("gvis", class(Page))#
plot(Page)#
pause()#
#
#
## See how googleVis functions can be integrated into rsp-files:#
browseRsp() ## Click on googleVis in the Package section.
?print.gvis
print(Page, file="~/Desktop/googleVis.html")
browseRsp()
AndrewGeo <- gvisGeoMap(Andrew, locationvar="LatLong", numvar="Speed_kt", #
      			 hovervar="Category", #
      		         options=list(height=350, region="US"))
AndrewGeo$html$chart
cat(AndrewGeo$html$chart)
?gvisTreeMap
require(datasets)
states3 <- data.frame(state.region, state.division, state.name, state.area)#
#
regions <- aggregate(list(region.area=states3$state.area),#
                     list(region=state.region), sum)#
#
divisions <- aggregate(list(division.area=states3$state.area),#
                     list(division=state.division, region=state.region),#
                     sum)#
#
my.states3 <- data.frame(regionid=c("USA",#
                                    as.character(regions$region),#
                                    as.character(divisions$division),#
                                    as.character(states3$state.name)),#
                         parentid=c(NA, rep("USA", 4), #
                                   as.character(divisions$region),#
                                   as.character(states3$state.division)),#
                         state.area=c(sum(states3$state.area),#
                                      regions$region.area,#
                                      divisions$division.area,#
                                      states3$state.area))#
#
my.states3$state.area.log=log(my.states3$state.area)#
#
statesTree3 <- gvisTreeMap(my.states3, "regionid", "parentid",#
                           "state.area", "state.area.log")#
#
## Not run: #
plot(statesTree3)
library(googleVis)
STock
Stock
Stock$Title
Stock$Title[5]
levles(Stock$Title)
levels(Stock$Title)
levels(Stock$Title)[1]
levels(Stock$Title)[1]="Bought Pencils"
Stock
levels(Stock$Title)[1]="Bought pencils"
Stock
save(Stock, file="~/Dropbox/google-motion-charts-with-r/data/Stock.RData")
#
 Date <- as.Date(paste("2008-1-", 1:6, sep=""))#
 Pencils <- c(3000, 14045, 5502, 75284, 41476, 333222)#
 Pencils.titles <-c(rep(NA,4), 'Bought pencils', NA)#
 Pencils.annotation <-c(rep(NA,4), 'Bought 200k pencils', NA)#
 Pens <- c(40645, 20374, 50766, 14334, 66467, 39463)#
 Pens.titles <- c(rep(NA, 3), 'Out of stock', NA, NA)#
 Pens.annotation <- c(rep(NA, 3), 'Ran of stock on pens at 4pm', NA, NA)#
#
 original.df=data.frame(Date, Pencils, Pencils.titles,#
                        Pencils.annotation, Pens, Pens.titles,#
                        Pens.annotation)  #
#
#
 Stock <- reshape(original.df, idvar="Date", times=c("Pencils", "Pens"), #
                  timevar="Device",#
                  varying=list(c("Pencils", "Pens"),#
                               c("Pencils.titles", "Pens.titles"),#
                               c("Pencils.annotation", "Pens.annotation")), #
                   v.names=c("Value", "Title", "Annotation"),#
                   direction="long")
Stock
Andrew
names(Andre)
names(Andrew)
names(Andrew)[3]
names(Andrew)[4]
names(Andrew)[4]="Pressure_mb"
save(Andrew, file="~/Dropbox/google-motion-charts-with-r/data/Andrew.RData")
browseRsp()
library(googleVis)
browseRsp()
library(ChainLadder)
 lRAA=as.data.frame(RAA, na.rm=TRUE)#
 lRAA$dev.year.end <- as.Date(with(lRAA, paste(dev,"-12-31", sep="")))#
 lRAA$title <- NA#
 lRAA$annotation <- NA#
 #
 lRAA$title[c(2,47)] <- c("Low first claim", "Negative development")#
 lRAA$annotation[c(2,47)] <- c("Change in underlying claims process resulted in delayed reporting", #
    "Joe Bloggs was on holiday and the person who covered for him#
 mixed up the signs.")
lRAA
head(lRAA)
plot(gvisAnnotatedTimeLine(lRAA, "dev.year.end", "value", "origin", "title", "annotation"))
plot(gvisAnnotatedTimeLine(lRAA, "dev.year.end", "value", "origin", "title", "annotation", options=list(displayAnnotation=TRUE)))
?gvisAnnotationTimeLine
?gvisAnnotatedTimeLine
plot(gvisAnnotatedTimeLine(lRAA, "dev.year.end", "value", "origin", "title", "annotation", options=list(displayAnnotations=TRUE)))
lRAA
head(lRAA)
?gvisAnnotatedTimeLine
as.Date("0000-01-01")
toJSON(as.Date("0000-01-01"))
  A <- gvisAnnotatedTimeLine(lRAA, datevar="dev.year.end", numvar="value", idvar="origin",#
                                   titlevar="title", annotationvar="annotation", #
                                   options=list(legendPosition='newRow',#
				   width=800, height=400,#
				   displayAnnotations=TRUE))#
 plot(A)
A$html$chart
cat(A$html$chart)
toJSON(as.Date("0-01-01"))
toJSON(as.Date("-0-01-01"))
toJSON(as.Date("00-01-01"))
A$html$chart
cat(A$html$chart)
 library(ChainLadder)#
 lRAA=as.data.frame(RAA, na.rm=TRUE)#
 lRAA$dev.year.end <- as.Date(with(lRAA, paste(dev,"-12-31", sep="")))#
 lRAA$title <- NA#
 lRAA$annotation <- NA#
 #
 lRAA$title[c(2,47)] <- c("Low first claim", "Negative development")#
 lRAA$annotation[c(2,47)] <- c("Change in underlying claims process resulted in delayed reporting", #
    "Joe Bloggs was on holiday and the person who covered for him#
 mixed up the signs.")	#
  A <- gvisAnnotatedTimeLine(lRAA, datevar="dev.year.end", numvar="value", idvar="origin",#
                                   titlevar="title", annotationvar="annotation", #
                                   options=list(legendPosition='newRow',#
				   width=800, height=400,#
				   displayAnnotations=TRUE))#
 plot(A)
toJSON(as.Date("00-01-01"))
toJSON(as.Date("01-01-01"))
q()
 library(googleVis)#
 library(ChainLadder) ## for the test data RAA#
 #
 lRAA=as.data.frame(RAA, na.rm=TRUE)#
 ## Convert dev year into a date#
 lRAA$dev.year.end <- as.Date(with(lRAA, paste(dev,"-12-31", sep="")))#
#
 ## Create a title and annotation columns #
 lRAA$title <- NA#
 lRAA$annotation <- NA#
 #
 ## Set some annotations#
 lRAA$title[c(2,47)] <- c("Low first claim", "Negative development")#
 lRAA$annotation[c(2,47)] <- c("Change in underlying claims process resulted in delayed reporting", #
    "Joe Bloggs was on holiday and the person who covered for him mixed up the signs.")	#
#
 ## So now lets plot the data lRAA#
 ## Create googleVis output#
 A <- gvisAnnotatedTimeLine(lRAA, datevar="dev.year.end", numvar="value", idvar="origin",#
                                   titlevar="title", annotationvar="annotation", #
                                   options=list(legendPosition='newRow',#
				   width=800, height=400,#
				   displayAnnotations=TRUE))
plot(A)
source("/Users/Markus/Desktop/ChainLadderGoogleVis.R")
example(gvisAnnotatedTimeLine)
?gvisAnnotatedTimeLine
data(Stock)#
Stock#
A1 <- gvisAnnotatedTimeLine(Stock, datevar="Date",#
                           numvar="Value", idvar="Device",#
                           titlevar="Title", annotationvar="Annotation",#
                           options=list(displayAnnotations=TRUE,#
                            width=600, height=350)#
                           )#
## Not run: #
plot(A1)
Stock#
A1 <- gvisAnnotatedTimeLine(Stock, datevar="Date",#
                           numvar="Value", idvar="Device",#
                           titlevar="Title", annotationvar="Annotation",#
                           options=list(displayAnnotations=TRUE,#
			    legendPosition='newRow',#
                            width=600, height=350)#
                           )
plot(A1)
Stock#
A1 <- gvisAnnotatedTimeLine(Stock, datevar="Date",#
                           numvar="Value", idvar="Device",#
                           #titlevar="Title", annotationvar="Annotation",#
                           options=list(displayAnnotations=TRUE,#
			    legendPosition='newRow',#
                            width=600, height=350)#
                           )
plot(A1)
Stock#
A1 <- gvisAnnotatedTimeLine(subset(Stock, Device=="Pen"), datevar="Date",#
                           numvar="Value", #idvar="Device",#
                           #titlevar="Title", annotationvar="Annotation",#
                           options=list(displayAnnotations=TRUE,#
			    legendPosition='newRow',#
                            width=600, height=350)#
                           )
Stock#
A1 <- gvisAnnotatedTimeLine(subset(Stock, Device=="Pens"), datevar="Date",#
                           numvar="Value", #idvar="Device",#
                           #titlevar="Title", annotationvar="Annotation",#
                           options=list(displayAnnotations=TRUE,#
			    legendPosition='newRow',#
                            width=600, height=350)#
                           )
plot(A1)
library(ChainLadder)
source("~/Mathematik/Dan Murphy/ata.r")
ata(GenIns)
ata(RAA)
ata(GenIns[1,])
ata(GenIns[1,drop=FALSE])
ata(GenIns[1,,drop=FALSE])
GenIns[1,,drop=FALSE]
ata(GenIns[1,,drop=FALSE])
ata(qincurred)
as.data.frame(qincurred)
X=as.data.frame(qincurred, rm.na=TRUE)
head(X)
ata(RAA)
ata(GenIns)
apply(ata(GenIns),2,mean, na.rm=TRUE)
MackChainLadder(GenIns)$f
MackChainLadder(GenIns, alpha=0)$f
library(Hmisc)
apply(ata(GenIns),2,wtd.mean, weights=GenIns, na.rm=TRUE)
apply(ata(GenIns),2,wtd.mean, weights=1/GenIns, na.rm=TRUE)
?wtd.mean
w=1/GenIns
w[is.na(w)]=0
apply(ata(GenIns),2,wtd.mean, weights=w, na.rm=TRUE)
apply(ata(GenIns),2,wtd.mean, weights=1, na.rm=TRUE)
apply(ata(GenIns),2,mean, weights=1, na.rm=TRUE)
apply(ata(GenIns),2,mean, weights=21, na.rm=TRUE)
apply(ata(GenIns),2,wtd.mean, weights=1, na.rm=TRUE)
apply(ata(GenIns),2,wtd.mean, weights=NULL, na.rm=TRUE)
wtd.mean
apply(ata(GenIns),2, function(x), mean(x), na.rm=TRUE)
apply(ata(GenIns),2, function(x) mean(x, na.rm=TRUE))
ata(GenIns)
ata(GenIns) %*% rep(1,9)
ata(GenIns) %*% t(rep(1,9))
t(ata(GenIns)) %*% rep(1,9)
ata(GenIns) %*% rep(1,9)
library(googleVis)
?gvisGeoMap
require(datasets)#
states <- data.frame(state.name, state.x77)#
#
G3 <- gvisGeoMap(states, "state.name", "Illiteracy",#
                 options=list(region="US", dataMode="regions",#
		 width=600, height=400))#
## Not run: #
plot(G3)
G3$html$chart
cat(G3$html$chart)
library(googleVis)
setwd("~/Dropbox/google-motion-charts-with-r/inst/gadgets/")
setwd("~/Dropbox/google-motion-charts-with-r/inst/gadgets/")
#
Motion=gvisMotionChart(Fruits, idvar="Fruit", timevar="Year", options=list(height=350, width=400))#
cat(createGoogleGadget(Motion), file="motionchart.xml")#
#
## Geo Map with coloured regions#
Geo=gvisGeoMap(Exports, locationvar="Country", numvar="Profit",#
                       options=list(height=350, dataMode='regions'))#
cat(createGoogleGadget(Geo), file="geomap.xml")#
#
#
## Show Hurricane Andrew (1992) storm track with Geo Map#
AndrewGeo <- gvisGeoMap(Andrew, locationvar="LatLong", numvar="Speed_kt", #
      			 hovervar="Category", #
      		         options=list(height=250, width=400 region="US"))#
#
cat(createGoogleGadget(AndrewGeo), file="andrewgeomap.xml")#
#
## Hurricane Andrew (1992) storm track with Google Maps#
AndrewMap <- gvisMap(Andrew, "LatLong" , "Tip", #
      	      options=list(showTip=TRUE, showLine=TRUE, enableScrollWheel=TRUE,#
		      mapType='terrain', useMapTypeControl=TRUE))#
#
cat(createGoogleGadget(AndrewMap), file="andrewmap.xml")#
#
#
## Table. Click on the column header to sort the rows #
Table <- gvisTable(Exports, options=list(width=400, height=300))#
cat(createGoogleGadget(Table), file="table.xml")#
#
## Table with embedded links#
PopTable <- gvisTable(Population, options=list(width=600, height=300, page='enable'))#
#
cat(createGoogleGadget(PopTable), file="poptable.xml")#
#
## Tree Map. Left mouse-click to drill down, right mouse-click to move up a hierarchy#
Tree <- gvisTreeMap(Regions,  "Region", "Parent", "Val", "Fac", options=list(fontSize=16))#
#
cat(createGoogleGadget(Tree), file="treemap.xml")#
#
require(datasets)#
states <- data.frame(state.name, state.area)#
#
states3 <- data.frame(state.region, state.division, state.name, state.area)#
#
regions <- aggregate(list(region.area=states3$state.area),#
                     list(region=state.region), sum)#
#
divisions <- aggregate(list(division.area=states3$state.area),#
                     list(division=state.division, region=state.region),#
                     sum)#
#
my.states3 <- data.frame(regionid=c("USA",#
                                    as.character(regions$region),#
                                    as.character(divisions$division),#
                                    as.character(states3$state.name)),#
                         parentid=c(NA, rep("USA", 4), #
                                   as.character(divisions$region),#
                                   as.character(states3$state.division)),#
                         state.area=c(sum(states3$state.area),#
                                      regions$region.area,#
                                      divisions$division.area,#
                                      states3$state.area))#
#
my.states3$state.area.log=log(my.states3$state.area)#
#
statesTree3 <- gvisTreeMap(my.states3, "regionid", "parentid",#
                           "state.area", "state.area.log", options=list(showScale=TRUE, width=400, height=300))#
#
cat(createGoogleGadget(statesTree3), file="statestreemap.xml")#
#
#
## Annotated Time Line Chart#
AnnoTimeLine  <- gvisAnnotatedTimeLine(Stock, datevar="Date",#
                           numvar="Value", idvar="Device",#
                           titlevar="Title", annotationvar="Annotation",#
                           options=list(displayAnnotations=TRUE,#
                             legendPosition='newRow',#
                             width=400, height=250)#
                           )#
cat(createGoogleGadget(AnnoTimeLine), file="annotimeline.xml")
#
Motion=gvisMotionChart(Fruits, idvar="Fruit", timevar="Year", options=list(height=350, width=400))#
cat(createGoogleGadget(Motion), file="motionchart.xml")#
#
## Geo Map with coloured regions#
Geo=gvisGeoMap(Exports, locationvar="Country", numvar="Profit",#
                       options=list(height=350, dataMode='regions'))#
cat(createGoogleGadget(Geo), file="geomap.xml")#
#
#
## Show Hurricane Andrew (1992) storm track with Geo Map#
AndrewGeo <- gvisGeoMap(Andrew, locationvar="LatLong", numvar="Speed_kt", #
      			 hovervar="Category", #
      		         options=list(height=250, width=400, region="US"))#
#
cat(createGoogleGadget(AndrewGeo), file="andrewgeomap.xml")#
#
## Hurricane Andrew (1992) storm track with Google Maps#
AndrewMap <- gvisMap(Andrew, "LatLong" , "Tip", #
      	      options=list(showTip=TRUE, showLine=TRUE, enableScrollWheel=TRUE,#
		      mapType='terrain', useMapTypeControl=TRUE))#
#
cat(createGoogleGadget(AndrewMap), file="andrewmap.xml")#
#
#
## Table. Click on the column header to sort the rows #
Table <- gvisTable(Exports, options=list(width=400, height=300))#
cat(createGoogleGadget(Table), file="table.xml")#
#
## Table with embedded links#
PopTable <- gvisTable(Population, options=list(width=600, height=300, page='enable'))#
#
cat(createGoogleGadget(PopTable), file="poptable.xml")#
#
## Tree Map. Left mouse-click to drill down, right mouse-click to move up a hierarchy#
Tree <- gvisTreeMap(Regions,  "Region", "Parent", "Val", "Fac", options=list(fontSize=16))#
#
cat(createGoogleGadget(Tree), file="treemap.xml")#
#
require(datasets)#
states <- data.frame(state.name, state.area)#
#
states3 <- data.frame(state.region, state.division, state.name, state.area)#
#
regions <- aggregate(list(region.area=states3$state.area),#
                     list(region=state.region), sum)#
#
divisions <- aggregate(list(division.area=states3$state.area),#
                     list(division=state.division, region=state.region),#
                     sum)#
#
my.states3 <- data.frame(regionid=c("USA",#
                                    as.character(regions$region),#
                                    as.character(divisions$division),#
                                    as.character(states3$state.name)),#
                         parentid=c(NA, rep("USA", 4), #
                                   as.character(divisions$region),#
                                   as.character(states3$state.division)),#
                         state.area=c(sum(states3$state.area),#
                                      regions$region.area,#
                                      divisions$division.area,#
                                      states3$state.area))#
#
my.states3$state.area.log=log(my.states3$state.area)#
#
statesTree3 <- gvisTreeMap(my.states3, "regionid", "parentid",#
                           "state.area", "state.area.log", options=list(showScale=TRUE, width=400, height=300))#
#
cat(createGoogleGadget(statesTree3), file="statestreemap.xml")#
#
#
## Annotated Time Line Chart#
AnnoTimeLine  <- gvisAnnotatedTimeLine(Stock, datevar="Date",#
                           numvar="Value", idvar="Device",#
                           titlevar="Title", annotationvar="Annotation",#
                           options=list(displayAnnotations=TRUE,#
                             legendPosition='newRow',#
                             width=400, height=250)#
                           )#
cat(createGoogleGadget(AnnoTimeLine), file="annotimeline.xml")
