Description Usage Arguments Details See Also Examples
Draw a time-series plot.
1 2 3 |
time |
the variable indicating time on the horizontal axis. |
y |
a vertor of all the variable names of interest. |
data |
Mutaframe data generated by |
group |
Similar to period, but is used for longitudinal data grouping. |
shift |
Wrapping speed selector. The default possible speeds are 1,7(for days a week),12(for months),24(for hours). |
size |
Point size, default to be 2. |
alpha |
Transparency level, 1=completely opaque, default to be 1. |
asp |
Ratio between width and height of the plot. |
series.stats |
Whether to show the statistics which measure the similarity between series when wrapping. It gives the ACF, corr, and R square for one, two, and more series respectively. |
fun.base |
a function to compute the baseline of the area plot |
main |
main title for the plot. |
xlab |
label on horizontal axis, default is name of x variable |
ylab |
label on vertical axis, default is name of y variable |
Arrow up/down: in-/de-crease size of points.
Arrow left/right: wrap the time series in the initial mode, and drag the series in the series selection mode.
Shift + right: Time series will be folded directly to the width of maximal value in argument shift.
Shift + left: Time series will be backed to the original xaxis position.
Key '+'/'-': de-/in-crease alpha level (starts at alpha=1 by default).
Key 'u'/'d': separate/mix the series groups or the period by shifting them up and down.
Shift + 'u'/'d': for multivariate y's, separate/mix them by shifting up and down.
Key 'g': change the wrapping period circularly in the values of parameter 'shift'.
Key 'm': Switch the mode for series selection. Default to be off. When there are more than one series in the plot, users can turn it on to hold a series and shift the series horizontally by dragging with the mouse.
Key 'y': y-wrapping
Shift + 'y': y-wrapping backward
Key 'r': switch to the area plot
Key 'f': fold the series to a horizon plot
Wheel: Zoom in/out. Then users can drag the series horizontally to see the details.
Other plots: qbar
; qboxplot
;
qdensity
; qhist
,
qspine
; qmval
;
qparallel
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | library(cranvas)
## example 1: NASA temperature data
nasa2221 <- subset(nasa, Gridx == 22 & Gridy == 21)
nasa2221$Year <- factor(nasa2221$Year)
qnasa <- qdata(nasa2221)
qtime(TimeIndx,ts,qnasa,shift=c(1,12))
qscatter(ts,ps_tovs,data=qnasa)
qtime("TimeIndx","ts",qnasa,Year,shift=c(1,12))
qtime(TimeIndx,c("ts","ca_med","ps_tovs"),qnasa,shift=c(1,12))
qtime("TimeIndx",c(ts,ca_med,ps_tovs),qnasa,Year)
##
nasa2221 <- subset(nasa, Gridx %in% c(14,17,20) & Gridy == 21)
#nasa2221 <- subset(nasa, Gridy == 21)
nasa2221$Year <- factor(nasa2221$Year)
nasa2221$Gridx <- factor(nasa2221$Gridx)
qnasa <- qdata(nasa2221)
qtime("TimeIndx",c(ts,ca_med,o3_tovs),qnasa,Gridx,shift=c(1,12))
qscatter(o3_tovs,ts,data=qnasa)
library(ggplot2)
nasa.locs <- subset(cranvas::nasa, TimeIndx == 1)
nasa.locs$loc <- paste(nasa.locs$Gridx, nasa.locs$Gridy, sep=",")
qplot(Long, Lat, data=nasa.locs, geom="text", label = loc)
## example 2: Remifentanil in the nlme package
library(nlme)
qRem <- qdata(Remifentanil[complete.cases(Remifentanil) & Remifentanil$ID==1,])
qtime(Time, conc, qRem)
Remi <- Remifentanil[complete.cases(Remifentanil),]
Remi$ID <- factor(Remi$ID)
qRemi <- qdata(Remi)
qtime(Time, conc, qRemi, group=ID)
qscatter(Amt, conc, data=qRemi)
# for categorical brushing self-link dataset by ID:
# id <- link_cat(qRemi, "ID")
# remove_link(qRemi, id)
## example 3: Wages
library(dplyr)
wages.num <- summarise(group_by(wages, id), n=length(lnw))
indx <- wages.num$id[wages.num$n > 11]
wages.sub <- subset(wages, id %in% indx)
nindiv <- length(unique(wages.sub$id))
wages.sub$idno <- factor(wages.sub$id, labels=1:nindiv)
wages.sub.demog <- summarise(group_by(wages.sub, idno), n=length(lnw),
avlnw = mean(lnw, na.rm=T),
#trendlnw = lsfit(exper, lnw)$coef[2],
trendlnw = max(lnw, na.rm=T) - min(lnw, na.rm=T),
black = black[1],
hispanic = hispanic[1],
ged = ged[1], hgc = hgc[1],
avunemp = mean(uerate, na.rm=T))
#qwage <- qdata(wages[as.integer(as.character(wages$id))<2000,1:3])
qwages <- qdata(wages.sub[,c(11,2:3)])
qtime(exper, lnw, qwages, group=idno)
# id <- link_cat(wage, "id")
# remove_link(wage, id)
indx <- wages.num$id[wages.num$n > 3]
wages.sub2 <- subset(wages, id %in% indx)
wages.sub2.demog <- summarise(group_by(wages.sub2, id), n=length(lnw),
avlnw = mean(lnw, na.rm=T),
#trendlnw = coefficients(lm(lnw ~ exper))[2],
rangelnw = max(lnw, na.rm=T) - min(lnw, na.rm=T),
sdlnw = sd(lnw, na.rm=T),
startlnw = lnw[1],
endlnw = lnw[length(lnw)],
inclnw = (lnw[length(lnw)]-lnw[1])/lnw[1]*100.0,
black = black[1],
hispanic = hispanic[1],
ged = ged[1], hgc = hgc[1],
avunemp = mean(uerate, na.rm=T))
qwages <- qdata(wages.sub2[,1:3])
qwages.demog <- qdata(wages.sub2.demog)
id = link_cat(qwages.demog, "id", qwages, "id")
qtime(exper, lnw, qwages, group=id)
qscatter(startlnw, inclnw, qwages.demog)
qbar(hgc, qwages.demog)
qhist(avunemp, qwages.demog)
remove_link(qwages.demog, id[1])
remove_link(qwages, id[2])
# Now need to link scatterplots of demographics with time series
## example 4: Lynx - for posterity
# Good to show off wrapping to investigate irregular series
qlynx <- qdata(data.frame(Time=1:114, lynx))
qtime(Time, lynx, qlynx, shift=1:13)
## example 5: Sunspots - for posterity
# Good to show off wrapping to investigate irregular series
qsun <- qdata(data.frame(Time=1:2820, sunspots))
qtime(Time, sunspots, qsun, shift=c(1,c(1,6,7,13,26)*10))
## example 6: Pigs
qpig <- qdata(pigs)
qtime(TIME, c("GILTS","PROFIT","PRODUCTION","HERDSZ"), qpig, shift=c(1,4))
## example 7: flu trends
flu.data <- read.table("http://www.google.org/flutrends/us/data.txt", skip=11, sep=",", header=TRUE)
# Get only states
flu.data <- flu.data[, c(1, 3:53)]
# Melt data, and rename variables
library(reshape)
flu.melt <- melt(flu.data, id.vars="Date")
flu.melt$Date <- as.Date(flu.melt$Date)
colnames(flu.melt)[2] <- "State"
colnames(flu.melt)[3] <- "FluSearches"
flu.melt$days <- as.vector(difftime(flu.melt$Date,as.Date('2002-12-31')))
summary(flu.melt$Date)
flu.melt$Date[flu.melt$days>2500&flu.melt$days<2520]
qflu <- qdata(flu.melt)
qtime(days, FluSearches, data=qflu, group="State",shift=c(1,7,28,364))
# winter of 2014
flu2014 <- subset(flu.melt, days>3960)
ord <- names(sort(tapply(flu2014$FluSearches,flu2014$State,function(x)which(x>(max(x)/5*3))[1])))
flu2014$State <- factor(flu2014$State,levels=ord)
qflu <- qdata(flu2014)
qtime(days, FluSearches, data=qflu, group="State",shift=c(1,7,28,35,91))
cranvas_off()
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.