Packages

  library("sf")
## Linking to GEOS 3.6.2, GDAL 2.2.3, PROJ 4.9.3
  library("sp")
  library("cartography")
  library("SpatialPosition")
## Loading required package: raster
  library("readxl")

Data Import

Data are avaiable online:

  com <- st_read("ign/COMMUNE.shp", quiet = T) 
  dpt <- st_read("ign/DEPARTEMENT.shp", quiet = T) 
  compop <- read.csv("insee/population2017.csv",header=TRUE,sep=",",dec=".",encoding="utf-8") 
  nd <- read_excel("data/NdB_April2016_France.xlsx", sheet = "data")
  nd <- as.data.frame(nd)  
  nd$INSEECode <- as.character(as.numeric(nd$INSEECode))

Dates & Weeks management

  prettydate <-function (x = NULL)
  {
    yyyy <- substr(x,1,4)
    mm <- substr(x,5,6)
    months <- c("January", "February","March","April","May","June","July","August","September","October","November","December")
    month <- months[as.numeric(mm)]
    dd <- substr(x,7,8)  
    str <- paste0 (month," ", dd, ", " ,yyyy)  
    return (str)
  }

  all <- c(min(nd$Date),max(nd$Date))
  week1 <- c(min(nd$Date),20160403)
  week2 <- c(20160404,20160410)
  week3 <- c(20160411,20160417)
  week4 <- c(20160418,20160424)
  week5 <- c(20160425,max(nd$Date))

PLOT 1 - Municipalities with more than 20,000 inhabitants

  par(mar = c(0,0,1.2,0))
  threshold <- 20000
  title <- paste("Municipalities with more than ",threshold," inhabitants, 2014", sep="")   
  com <- merge(x = com, y = compop, by.x = "INSEE_COM" , by.y = "id")
  cities <- st_centroid(x = com[com$pop >= threshold,], of_largest_polygon = FALSE)
## Warning in st_centroid.sf(x = com[com$pop >= threshold, ],
## of_largest_polygon = FALSE): st_centroid assumes attributes are constant
## over geometries of x
  plot(st_geometry(dpt),col="#afc3db", border="#eff4f9")
  plot(st_geometry(cities), pch=21, col="#00060f", bg="#0a2247", lwd=1, cex=0.8, add=T)
  layoutLayer(title = title, sources = "INSEE, 2018", 
              author = "Nicolas Lambert, 2018", theme = "blue.pal", scale = NULL)
  barscale(size = 100, lwd = 1.5, cex = 0.6, style = "pretty")

PLOT 2 - Nuit Debout (all)

  par(mar = c(0,0,1.2,0))
  beginning <- prettydate(min(nd$Date))
  end <- prettydate(max(nd$Date))
  title <- paste("Nuit Debout Assemblies (" , beginning, " - ", end , ")" , sep="")   
  prj <- st_crs(com)$proj4string
  nd_sf <- st_as_sf(nd, coords = c("Longitude", "Latitude"),crs=4326)
  nd_sf <- st_transform(nd_sf,2154) 
  plot(st_geometry(dpt),col="#afc3db", border="#eff4f9")
  plot(st_geometry(nd_sf),  pch=21, col="#991313", bg="#db3232", lwd=1, cex=0.8, add=T)
  layoutLayer(title = title, 
              author = "Nicolas Lambert, 2018", theme = "blue.pal", scale = NULL)
  barscale(size = 100, lwd = 1.5, cex = 0.6, style = "pretty")

PLOT 3 - Nuit Debout meetings by Municipalities

  par(mar = c(0,0,1.2,0))
 plotmap <-function (timeextant = all, inches = 0.15, col="red") {
  beginning <- prettydate(timeextant[1])
  end <- prettydate(timeextant[2])
  
  
  # nd by municipalities
  nd_sf_tmp <- nd_sf[nd_sf$Date >= timeextant[1] & nd_sf$Date <= timeextant[2],]
  nd_tmp <- nd[nd$Date >= timeextant[1] & nd$Date <= timeextant[2],]
  codesinsee <- levels(as.factor(nd_sf_tmp$INSEECode))
  nd2 <- table(factor(nd_sf_tmp$INSEECode, levels = codesinsee))
  nd2 <- as.data.frame(nd2)
  colnames(nd2) <- c("id","count")
  nd2 <- nd2[nd2$count>0,]
  nd2 <- data.frame(nd2, nd_tmp[match(nd2[,"id"], nd_tmp[,"INSEECode"]),c("Latitude","Longitude")])
  nd2_sf <- st_as_sf(nd2, coords = c("Longitude", "Latitude"),crs=4326)
  nd2_sf <- st_transform(nd2_sf,2154) 
  
  # Links
  mydist <- 100000
  m <- st_distance(st_geometry(nd2_sf))
  units(m) <- NULL
  rownames(m) <-   nd2_sf$id
  colnames(m) <-   nd2_sf$id
  dist <- reshape2::melt(m,variable.name=1, na.rm=TRUE)
  colnames(dist) <- c("i","j","fij")
  dist <- dist[dist$fij <=mydist,]
  links_sf <- getLinkLayer(x = nd2_sf, xid = "id", df = dist, dfid =  c("i", "j"))

  # cartography
  plot(st_geometry(dpt),col="#afc3db", border="#eff4f9")
  # Links
  plot(st_geometry(links_sf), col = "#6480af25", lwd = 2, add=T)
  # Circles
  propSymbolsLayer(x = nd2_sf,var = "count", inches= inches, legend.title.txt = "Number of Assemblies", legend.style = "e", fixmax = 10, col = col)
  # Layout
  title <- paste("Nuit Debout Assemblies by Municipalities (" , beginning, " - ", end , ")" , sep="")   
  layoutLayer(title =title, 
              author = "Nicolas Lambert, 2018", theme = "blue.pal", scale = NULL)
  barscale(size = 100, lwd = 1.5, cex = 0.6, style = "pretty")
  
  }
  
  plotmap(week1, inches = 0.15, col="#7abadb") 

  plotmap(week2, inches = 0.15, col="#7abadb") 
## Warning: 155 links were not created. Some dfid were not found in xid

  plotmap(week3, inches = 0.15, col="#7abadb") 
## Warning: 291 links were not created. Some dfid were not found in xid

  plotmap(week4, inches = 0.15, col="#7abadb") 
## Warning: 347 links were not created. Some dfid were not found in xid

  plotmap(week5, inches = 0.15, col="#7abadb") 
## Warning: 752 links were not created. Some dfid were not found in xid

  plotmap(all, inches = 0.08, col="#ff3700") 
## Warning: 435 links were not created. Some dfid were not found in xid

PLOT 4 - Days

  datetoday <-function (x = NULL)
  {
    days <- c("Friday","Saturday","Sunday","Monday","Tuesday","Wednesday","Thursday")
    nbdays2016 <- c(31,29,31,30,31,30,31,31,30,31,30,31) 
    days2 <- rep(days,length.out=366)
    mm <- as.numeric(substr(x,5,6))
    dd <- as.numeric(
      substr(x,7,8))  
    dayoftheyear <- sum(nbdays2016[1:mm-1]) + dd
    day <- days2[dayoftheyear]
    return(day)
  }
  
  
  dayplot <-function (timeextant = all, col="red"){
    debut <- prettydate(timeextant[1])
    fin <- prettydate(timeextant[2])
    nd_sf2 <- nd_sf[nd_sf$Date >= timeextant[1] & nd_sf$Date <= timeextant[2],]
  for (i in 1:dim(nd_sf2)[1])
  {
    nd_sf2$day[i] <- datetoday(nd_sf2$Date[i])
  }

  days <- table(factor(nd_sf2$day, levels = c("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday")))  
  days <- as.data.frame(days)
  colnames(days) <- c("day","count")
  title <- paste("Day of assembly\n(",debut, " - ",fin,")",sep="")
  barplot(days$count, main=title, xlab="Days", ylab="Number of Assemblies", names.arg=days$day,
          border="#353333",col=col)
  }
  
  dayplot(week1, col = "#7abadb")

  dayplot(week2, col = "#7abadb")

  dayplot(week3, col = "#7abadb")

  dayplot(week4, col = "#7abadb")

  dayplot(week5, col = "#7abadb")

  dayplot(all, col = "#ff3700")