26
26
# ' @param point.size an integer indicating the size of point to be used for incidence
27
27
# ' @param annot.size an integer indicating the size of the text annotations
28
28
# ' @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
29
30
# '
30
31
# ' @author Thibaut Jombart \email{thibautjombart@@gmail.com}
31
32
# '
34
35
# '
35
36
# ' @examples
36
37
# ' \dontrun{
38
+ # '
37
39
# ' 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
+ # '
39
44
# ' }
40
45
# '
41
46
# '
42
-
43
47
# #################
44
48
# # mapIncidence ##
45
49
# #################
@@ -48,8 +52,9 @@ mapIncidence <- function(x, dates, lon, lat, fill.by=NULL, col.pal=0, alpha=.5,
48
52
start.at = NULL , stop.at = NULL , xlab = NULL , ylab = " Incidence" ,
49
53
date.format = " %d %b %Y" , angle = 90 , xbreaks = " 1 week" ,
50
54
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
+
53
58
# # HANDLE ARGUMENTS ##
54
59
if (is.numeric(dates )) dates <- names(x )[dates ]
55
60
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,
106
111
max(x [,lat ],na.rm = TRUE )))
107
112
108
113
# # fectch map
114
+ filename <- paste(path ," ggmapTemp.png" ,sep = " /" )
109
115
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 ))
111
117
} 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 ))
113
119
}
114
120
115
121
# # compute cumulative incidence
@@ -127,6 +133,11 @@ mapIncidence <- function(x, dates, lon, lat, fill.by=NULL, col.pal=0, alpha=.5,
127
133
128
134
129
135
# # GENERATE THE MOVIE ##
136
+ # # set working directory
137
+ odir <- getwd()
138
+ on.exit(setwd(odir ))
139
+ setwd(path )
140
+
130
141
saveHTML({
131
142
for (i in 2 : length(dates.breaks )){
132
143
# # TOP PANEL: MAP
@@ -144,7 +155,7 @@ mapIncidence <- function(x, dates, lon, lat, fill.by=NULL, col.pal=0, alpha=.5,
144
155
alpha = .5 , col = " black" )) +
145
156
geom_jitter(data = x [toKeep ,], aes_string(x = lon ,y = lat ,colour = fill.by ),
146
157
alpha = alpha , size = point.size ,
147
- position = position_jitter(h = jitter / 2 , w = jitter )) +
158
+ position = position_jitter(height = jitter / 2 , width = jitter )) +
148
159
scale_size_continuous(" Cumulative \n incidence" , range = c(2 ,15 ),
149
160
limits = c(0 ,map.max.size ), breaks = map.breaks ) +
150
161
theme_bw() + labs(x = NULL ,y = NULL ) +
0 commit comments