Skip to content

Instantly share code, notes, and snippets.

@mages
mages / ww2.R
Last active August 29, 2015 13:57
require(timeline)
require(googleVis)
data(ww2)
ww2$Person <- gsub("\\n" ," ", ww2$Person)
plot(gvisTimeline(ww2, barlabel="Person", rowlabel="Group",
start="StartDate", end="EndDate",
options=list(width=590), chartid="ww2")
)
require(googleVis) ## googleVis 0.5.0-3
dat <- data.frame(Room=c("Room 1","Room 2","Room 3"),
Language=c("English", "German", "French"),
start=as.POSIXct(c("2014-03-14 14:00",
"2014-03-14 15:00",
"2014-03-14 14:30")),
end=as.POSIXct(c("2014-03-14 15:00",
"2014-03-14 16:00",
"2014-03-14 15:30")))
plot(
plot(
gvisTimeline(data=dat,
rowlabel="Language", barlabel="Room",
start="start", end="end", chartid="Languages")
)
require(igraph)
require(googleVis)
g <- graph.tree(24, children = 4)
set.seed(123)
E(g)$weight = rpois(23, 4) + 1
edgelist <- get.data.frame(g)
colnames(edgelist) <- c("source","target","value")
edgelist$source <- LETTERS[edgelist$source]
edgelist$target <- LETTERS[edgelist$target]
# See also the entry on stackoverflow: http://goo.gl/KUvmW2
library(lattice)
library(chron)
source("http://blog.revolutionanalytics.com/downloads/calendarHeat.R")
# Plot as calendar heatmap
calendarHeat(stock.data$Date, stock.data$Adj.Close,
varname="MSFT Adjusted Close")
stock <- "MSFT"
start.date <- "2012-01-01"
end.date <- Sys.Date()
quote <- paste("http://ichart.finance.yahoo.com/table.csv?s=",
stock,
"&a=", substr(start.date,6,7),
"&b=", substr(start.date, 9, 10),
"&c=", substr(start.date, 1,4),
"&d=", substr(end.date,6,7),
"&e=", substr(end.date, 9, 10),
## Uncomment the next 3 lines to install the developer version of googleVis
# install.packages(c("devtools","RJSONIO", "knitr", "shiny", "httpuv"))
# library(devtools)
# install_github("mages/googleVis")
library(googleVis)
Stock
# Date Device Value Title Annotation
# 1 2008-01-01 Pencils 3000 <NA> <NA>
# 2 2008-01-02 Pencils 14045 <NA> <NA>
# 3 2008-01-03 Pencils 5502 <NA> <NA>
set.seed(123)
dat=data.frame(A=rpois(100, 20),
B=rpois(100, 5),
C=rpois(100, 50))
plot(
gvisHistogram(dat, options=list(
legend="{ position: 'top', maxLines: 2 }",
colors="['#5C3292', '#1A8763', '#871B47']",
width=600),
chartid="Histogram")
library(googleVis)
dat=data.frame(label=c("A", "B", "C"),
val1=c(10,13,14),
val2=c(23,12,32))
plot(
gvisLineChart(dat, xvar="label", yvar=c("val1","val2"),
options=list(width=500,height=350,
title="Customising lines",
series="[{color:'green', targetAxisIndex: 0,
lineWidth: 1,
library(googleVis)
M <- matrix(nrow=6,ncol=6)
M[col(M)==row(M)] <- 1:6
dat <- data.frame(X=1:6, M)
plot(
gvisScatterChart(dat,
options=list(width=500,height=350,
title="Customising points",
legend="right",
pointSize=30,