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# '
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 \n incidence" , range = c(2 ,15 ),
149160 limits = c(0 ,map.max.size ), breaks = map.breaks ) +
150161 theme_bw() + labs(x = NULL ,y = NULL ) +
0 commit comments