@@ -7,6 +7,7 @@ library(gridExtra)
7
7
library(stringr )
8
8
library(htmltools )
9
9
library(tidyr )
10
+ library(leaflet.providers )
10
11
11
12
# Site map
12
13
create_map <- function (colonies ){
@@ -59,8 +60,22 @@ filter_annotations<-function(raw_data){
59
60
return (selected_boxes )
60
61
}
61
62
62
- totals_plot <- function (selected_boxes ){
63
- ggplot(selected_boxes ) + geom_bar(aes(x = species )) + coord_flip() + ggtitle(" Project Total" ) + labs(x = " Label" ) + theme(text = element_text(size = 20 ))
63
+ species_colors <- colorFactor(palette = c(" yellow" , " blue" ,
64
+ " #ff007f" , " brown" ,
65
+ " purple" , " white" ),
66
+ domain = c(" Great Egret" , " Great Blue Heron" ,
67
+ " Roseate Spoonbill" , " Wood Stork" ,
68
+ " Snowy Egret" , " White Ibis" ),
69
+ ordered = TRUE )
70
+
71
+ totals_plot <- function (selected_boxes ) {
72
+ ggplot(selected_boxes , aes(x = species , fill = species_colors(species ))) +
73
+ geom_bar() + coord_flip() + ggtitle(" Project Total" ) + labs(x = " Label" ) +
74
+ scale_fill_identity(guide = " none" ) +
75
+ theme(
76
+ text = element_text(size = 20 ),
77
+ panel.background = element_rect(fill = " #add8e6" )
78
+ )
64
79
}
65
80
66
81
site_totals <- function (selected_boxes ){
@@ -77,21 +92,20 @@ site_phenology<-function(selected_boxes){
77
92
theme(text = element_text(size = 20 ))
78
93
}
79
94
80
- plot_annotations <- function (selected_boxes , MAPBOX_ACCESS_TOKEN ){
81
- pal <- colorFactor(
82
- palette = ' Dark2' ,
83
- domain = selected_boxes $ species
84
- )
85
-
86
- selected_centroids <- st_transform(selected_boxes ,4326 )
95
+ plot_annotations <- function (selected_boxes , MAPBOX_ACCESS_TOKEN ) {
96
+ pal <- colorFactor(palette = " Dark2" , domain = selected_boxes $ species )
97
+
98
+ # Convert polygons to centroids
99
+ selected_centroids <- st_centroid(selected_boxes )
100
+ selected_centroids <- st_transform(selected_centroids , 4326 )
87
101
88
- # Create mapbox tileset
89
- mapbox_tileset <- unique(selected_centroids $ tileset_id )
90
- mapbox_tileset <- paste(" bweinstein." ,mapbox_tileset ,sep = " " )
102
+ # Create mapbox tileset
103
+ mapbox_tileset <- unique(selected_centroids $ tileset_id )
104
+ mapbox_tileset <- paste(" bweinstein." , mapbox_tileset , sep = " " )
91
105
92
- m <- leaflet(data = selected_centroids ) %> %
93
- addProviderTiles(" MapBox" , options = providerTileOptions(id = mapbox_tileset , minZoom = 8 , maxNativeZoom = 24 , maxZoom = 24 , accessToken = MAPBOX_ACCESS_TOKEN )) %> %
94
- addCircles(stroke = T ,color = ~ pal(species ),fillOpacity = 0.1 ,radius = 0.25 ,popup = ~ htmlEscape(label ))
106
+ m <- leaflet(data = selected_centroids ) %> %
107
+ addProviderTiles(" MapBox" , options = providerTileOptions(id = mapbox_tileset , minZoom = 8 , maxNativeZoom = 24 , maxZoom = 24 , accessToken = MAPBOX_ACCESS_TOKEN )) %> %
108
+ addCircles(stroke = T , color = ~ pal(species ),fillOpacity = 0.1 , radius = 0.25 , popup = ~ htmlEscape(label ))
95
109
return (m )
96
110
}
97
111
@@ -152,21 +166,13 @@ nest_history<-function(dat){
152
166
theme(axis.text.x = element_text(angle = - 90 ),text = element_text(size = 20 ))
153
167
}
154
168
155
- species_colors <- colorFactor(palette = c(" yellow" , " blue" ,
156
- " #ff007f" , " brown" ,
157
- " purple" , " white" ),
158
- domain = c(" Great Egret" , " Great Blue Heron" ,
159
- " Roseate Spoonbill" , " Wood Stork" ,
160
- " Snowy Egret" , " White Ibis" ),
161
- ordered = TRUE )
162
-
163
169
plot_nests <- function (df , bird_df , MAPBOX_ACCESS_TOKEN ){
164
170
mapbox_tileset <- unique(bird_df $ tileset_id )[1 ]
165
171
mapbox_tileset <- paste(" bweinstein." ,mapbox_tileset ,sep = " " )
166
172
167
173
m <- leaflet(data = df ) %> %
168
174
addProviderTiles(" MapBox" , layerId = " mapbox_id" ,options = providerTileOptions(id = mapbox_tileset , minZoom = 8 , maxNativeZoom = 24 , maxZoom = 24 , accessToken = MAPBOX_ACCESS_TOKEN )) %> %
169
- addCircles(stroke = T ,fillOpacity = 0.1 ,radius = 0.5 ,popup = ~ htmlEscape(paste(round(sum_top1 / num_obs_to ,2 ),nest_id ,sep = " :" ))) %> %
175
+ addCircles(stroke = T ,fillOpacity = 0.1 ,radius = 0.5 ,popup = ~ htmlEscape(paste(round(sum_top1 / num_obs ,2 ),nest_id ,sep = " :" ))) %> %
170
176
addCircles(data = bird_df , stroke = T , fillOpacity = 0 , radius = 0.2 , color = ~ species_colors(label ),
171
177
popup = ~ htmlEscape(paste(round(score ,2 ), bird_id , sep = " :" )))
172
178
return (m )
@@ -193,7 +199,7 @@ update_nests<-function(mapbox_tileset, df, bird_df, show_nests, show_birds,
193
199
}
194
200
if (show_nests ) {
195
201
map <- map %> %
196
- addCircles(data = df ,stroke = T ,fillOpacity = 0.1 ,radius = 0.5 ,popup = ~ htmlEscape(paste(round(sum_top1 / num_obs_to ,2 ),nest_id ,sep = " , " )))
202
+ addCircles(data = df ,stroke = T ,fillOpacity = 0.1 ,radius = 0.5 ,popup = ~ htmlEscape(paste(round(sum_top1 / num_obs ,2 ),nest_id ,sep = " , " )))
197
203
}
198
204
if (show_birds ) {
199
205
map <- map %> %
@@ -215,10 +221,9 @@ zooniverse_complete<-function(){
215
221
subject_data <- read.csv(" data/everglades-watch-subjects.csv" )
216
222
raw_annotations <- read.csv(" data/parsed_annotations.csv" )
217
223
subject_data $ Site <- sapply(subject_data $ metadata , function (x ) str_match(gsub(' \" ' , " " , x , fixed = TRUE )," site:(\\ w+)" )[,2 ])
218
-
219
224
# images per site
220
225
completed <- subject_data %> % group_by(Site ) %> % mutate(annotated = subject_id %in% raw_annotations $ subject_ids ) %> % select(Site ,subject_id , annotated ) %> % group_by(Site , annotated ) %> % summarize(n = n_distinct(subject_id )) %> %
221
226
tidyr :: spread(annotated ,n , fill = 0 ) %> % mutate(Percent_Complete = `TRUE` / (`TRUE` + `FALSE` )* 100 )
222
227
p <- ggplot(completed ,aes(x = Site ,y = Percent_Complete )) + coord_flip() + geom_bar(stat = " identity" ) + labs(y = " Annotated (%)" ,x = " Subject Set" )
223
228
return (p )
224
- }
229
+ }
0 commit comments