Visualisation of the 2014 Ebola outbreak in Sierra Leone

I have been trying to implement ''the Visualisation of the 2014 Ebola outbreak in Sierra Leone'' using ggplot2 and gganimate as described in the Article available at https://aberdeenstudygroup.github.io/studyGroup/lessons/Visualising%20Spatial%20Data/Visualising_Spatial_Data_in_R/ using the shp files available at https://data.humdata.org/dataset/a4816317-a913-4619-b1e9-d89e21c056b4 and the dataset available at https://github.com/AberdeenStudyGroup/SG-T14_ggmap_gganimate/blob/master/SG-T14-data/ebola.csv (just for simplicity to follow).

My challenge is in the second plot (ebola_plot_sub) which is obtained by combining the ebola dataset and the shp information by using the below codes as described in the article. The plot I'm getting has a lot of lines crossing each other different from what is presented in the original writing, (ie. totally distorting country map margins).

(Note: the animation part for the entire dataset is a bit tricky because of the changes in the package but can forget about it for know).

The LHS image is just the plot of shapefile as described in the article codes, the middle image is the one that I'm getting after implementing the codes for ebola sub plot which has a lot of lines crossing each other in the map, which weren't supposed to be there, and the last image is something similar to what I was supposed to be getting as described in the codes.

ebola <- read.csv("ebola.csv")

ebola <- gather(ebola,key="date",value="cases",-admin2Name) ##convert to long format

ebola_data <- merge(SL.df,ebola,by="admin2Name")

## Subset the ebola data to plot just one week
ebola_data_sub <- ebola_data[ebola_data$date.y=="X.2014.W51.",] 

#ebola_data_sub <- ebola_data[ebola_data$date.x=="X.2014.W51.",] #if the above code fails try this one

## create ggplot object ##
ebola_plot_sub <- ggplot(data = ebola_data_sub, aes(x = long, y = lat, group=group)) +
  geom_polygon(aes(fill = cases),color="black") +
  scale_fill_gradient(low = "#fcfbfd", high = "#2d004b") +
  coord_map() + theme_minimal()

You should strive to provide all data and code so the example is completely stand alone. In your example, it's not clear how the SL.df object is being created so there's a risk that what follows will be a waste of time.

I've assumed you're using the sf package and I've found a suitable shape file that can be easily downloaded. I've also given a link to the ebola.csv file. Hopefully this will give you enough to go on.

library(tidyr)
library(rgdal)
library(ggplot2)
library(gganimate)
library(animation)
library(sp)
# Download the 8 files needed from 
# https://github.com/AberdeenStudyGroup/SG-T14_ggmap_gganimate/raw/master/SG-T14-data/Sierra_leone/sle_admbnda_adm2_1m_gov_ocha.shp
# Other files apart from the one above are needed
# And change the folder where the download is
SL.df <- st_read('Sierra_leone/sle_admbnda_adm2_1m_gov_ocha.shp')

# Download this file from 
# https://raw.githubusercontent.com/AberdeenStudyGroup/SG-T14_ggmap_gganimate/master/SG-T14-data/ebola.csv
# Change the folder for you
ebola <- read.csv('ebola.csv')
ebola_long <- gather(ebola, key='date', value='cases', -admin2Name)

# Merge shape and Ebola data and select one week
ebola_data <- merge(SL.df,ebola_long,by="admin2Name")
ebola_data_sub <- ebola_data[ebola_data$date.y=="X.2014.W51.",] 

# Plot - this uses geom_sf
ebola_plot_sub <- 
    ggplot(ebola_data_sub) + 
    geom_sf(aes(fill=cases)) + 
    scale_fill_gradient(low = "#fcfbfd", high = "#2d004b") + 
    theme_minimal() 

ebola_plot_sub

Example Ebola image