Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 600d963

Browse files
committedFeb 13, 2015
plotIncidence now passes the check
1 parent 0493738 commit 600d963

File tree

4 files changed

+30
-11
lines changed

4 files changed

+30
-11
lines changed
 

‎plotIncidence/DESCRIPTION

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Title: Graphics for Incidence Time Series
33
Version: 0.0.0.9000
44
Authors@R: person("Thibaut", "Jombart", , "thibautjombart@gmail.com", role = c("aut", "cre"))
55
Description: This package provides graphical resources to visualise incidence time series from outbreak linelist data.
6-
Depends: R (>= 3.1.2)
6+
Depends: R (>= 3.1.2), ggplot2
77
License: GPL-2
88
LazyData: true
9-
Imports: ggplot2, scales, ggmap, gridExtra, OutbreakTools, animation
9+
Imports: scales, ggmap, gridExtra, OutbreakTools, animation

‎plotIncidence/R/globalVariables.R

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
## hack to get rid of warnings
2+
if(getRversion() >= "2.15.1") utils::globalVariables(c("y","Incidence"))

‎plotIncidence/R/mapIncidence.R

+18-7
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#' @param point.size an integer indicating the size of point to be used for incidence
2727
#' @param annot.size an integer indicating the size of the text annotations
2828
#' @param xy.annot a logical indicating whether latitudes and longitudes should be shown
29+
#' @param path a character string indicating the path used to save the created files
2930
#'
3031
#' @author Thibaut Jombart \email{thibautjombart@@gmail.com}
3132
#'
@@ -34,12 +35,15 @@
3435
#'
3536
#' @examples
3637
#' \dontrun{
38+
#'
3739
#' data(zombie_outbreak)
38-
#' mapIncidence(head(zombie_outbreak,1000), 3,"x.coord","y.coord", fill.by="gender",zoom=11)
40+
#' mapIncidence(head(zombie_outbreak,1000), 3,
41+
#' "x.coord","y.coord", fill.by="gender",
42+
#' zoom=11)
43+
#'
3944
#' }
4045
#'
4146
#'
42-
4347
##################
4448
## mapIncidence ##
4549
##################
@@ -48,8 +52,9 @@ mapIncidence <- function(x, dates, lon, lat, fill.by=NULL, col.pal=0, alpha=.5,
4852
start.at=NULL, stop.at=NULL, xlab=NULL, ylab="Incidence",
4953
date.format="%d %b %Y", angle=90, xbreaks="1 week",
5054
heights=c(0.75, 0.25), ani.width=800, ani.height=ani.width,
51-
point.size=5, annot.size=20, xy.annot=FALSE) {
52-
55+
point.size=5, annot.size=20, xy.annot=FALSE,
56+
path=tempdir()) {
57+
5358
## HANDLE ARGUMENTS ##
5459
if(is.numeric(dates)) dates <- names(x)[dates]
5560
if(is.numeric(lon)) lon <- names(x)[lon]
@@ -106,10 +111,11 @@ mapIncidence <- function(x, dates, lon, lat, fill.by=NULL, col.pal=0, alpha=.5,
106111
max(x[,lat],na.rm=TRUE)))
107112

108113
## fectch map
114+
filename <- paste(path,"ggmapTemp.png",sep="/")
109115
if(is.null(zoom)) {
110-
base.map <- ggmap(get_map(bound.box + c(-1,-1,1,1), source=source))
116+
base.map <- ggmap(get_map(bound.box + c(-1,-1,1,1), source=source, filename=filename))
111117
} else {
112-
base.map <- ggmap(get_map(bound.box + c(-1,-1,1,1), source=source, zoom=zoom))
118+
base.map <- ggmap(get_map(bound.box + c(-1,-1,1,1), source=source, zoom=zoom, filename=filename))
113119
}
114120

115121
## compute cumulative incidence
@@ -127,6 +133,11 @@ mapIncidence <- function(x, dates, lon, lat, fill.by=NULL, col.pal=0, alpha=.5,
127133

128134

129135
## GENERATE THE MOVIE ##
136+
## set working directory
137+
odir <- getwd()
138+
on.exit(setwd(odir))
139+
setwd(path)
140+
130141
saveHTML({
131142
for(i in 2:length(dates.breaks)){
132143
## TOP PANEL: MAP
@@ -144,7 +155,7 @@ mapIncidence <- function(x, dates, lon, lat, fill.by=NULL, col.pal=0, alpha=.5,
144155
alpha=.5, col="black")) +
145156
geom_jitter(data=x[toKeep,], aes_string(x=lon,y=lat,colour=fill.by),
146157
alpha=alpha, size=point.size,
147-
position = position_jitter(h=jitter/2, w=jitter)) +
158+
position = position_jitter(height=jitter/2, width=jitter)) +
148159
scale_size_continuous("Cumulative \nincidence", range=c(2,15),
149160
limits=c(0,map.max.size), breaks=map.breaks) +
150161
theme_bw() + labs(x=NULL,y=NULL) +

‎plotIncidence/man/mapIncidence.Rd

+8-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ mapIncidence(x, dates, lon, lat, fill.by = NULL, col.pal = 0, alpha = 0.5,
99
start.at = NULL, stop.at = NULL, xlab = NULL, ylab = "Incidence",
1010
date.format = "\%d \%b \%Y", angle = 90, xbreaks = "1 week",
1111
heights = c(0.75, 0.25), ani.width = 800, ani.height = ani.width,
12-
point.size = 5, annot.size = 20, xy.annot = FALSE)
12+
point.size = 5, annot.size = 20, xy.annot = FALSE, path = tempdir())
1313
}
1414
\arguments{
1515
\item{x}{a data.frame containing the data to be plotted.}
@@ -59,14 +59,20 @@ mapIncidence(x, dates, lon, lat, fill.by = NULL, col.pal = 0, alpha = 0.5,
5959
\item{annot.size}{an integer indicating the size of the text annotations}
6060

6161
\item{xy.annot}{a logical indicating whether latitudes and longitudes should be shown}
62+
63+
\item{path}{a character string indicating the path used to save the created files}
6264
}
6365
\description{
6466
This function provides advanced plotting facilities for incidence time series using ggplot2
6567
}
6668
\examples{
6769
\dontrun{
70+
6871
data(zombie_outbreak)
69-
mapIncidence(head(zombie_outbreak,1000), 3,"x.coord","y.coord", fill.by="gender")
72+
mapIncidence(head(zombie_outbreak,1000), 3,
73+
"x.coord","y.coord", fill.by="gender",
74+
zoom=11)
75+
7076
}
7177
}
7278
\author{

0 commit comments

Comments
 (0)
Please sign in to comment.