This R - notebook describes the geographical distribution of the cowpea accessions collected by Dr Alihu Ramatu from University of Ahmadu-Bello in Zaria. The location was plotted by Magda Julkowska to create an overview of all accessions.
Since Dr. Ramatu collected all of the data using the degrees and minutes - we need to recalculate them to coordinates that can be plotted in R. For this purpose - we will need to split the data and re-calculate:
setwd("/Users/magda/Dropbox/DataAndAnalysis/cowpea/Nigerian_population/accession map/")
list.files(pattern="csv")
## [1] "COWPEA ACCESSIONS RAMAT.csv" "COWPEA ACCESSIONS RAMATnew.csv"
cowpea <- read.csv("COWPEA ACCESSIONS RAMAT.csv", header = T)
head(cowpea)
In the above table - I splitted the Latitude and Longitude per degree symbol and ’ and " symbols to be uniform into Lat/Lon 1/2/3.
I then re-calculated the alternative GPS coodinates using the following formula:
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
# install.packages("splitstackshape")
library(splitstackshape)
new_cowpea <- cowpea %>% transmute(Lat_new = Lat1 + Lat2 / 60 + Lat3 / 60^2,
Long_new = Lon1 + Lon2 / 60 + Lon3 / 60^2)
new_cowpea$Accession.No <- cowpea$Accession.No
new_cowpea$Accession.Name <- cowpea$Accession.Name
new_cowpea$Entry.name <- cowpea$Entry.Name
new_cowpea
Once we have the new coodinates - I made sure that the new latitude and longitude are read by R as numeric and I plotted the map:
library(ggmap)
## Loading required package: ggplot2
## Google's Terms of Service: https://cloud.google.com/maps-platform/terms/.
## Please cite ggmap if you use it! See citation("ggmap") for details.
# register_google(key = ???)
new_cowpea$Lat_new <- as.numeric(as.character(new_cowpea$Lat_new))
new_cowpea$Long_new <- as.numeric(as.character(new_cowpea$Long_new))
new_cowpea
?register_google
map <- get_map(location = c(lon = 8.5, lat = 9.5), zoom = 6, maptype = "terrain")
## Source : https://maps.googleapis.com/maps/api/staticmap?center=9.5,8.5&zoom=6&size=640x640&scale=2&maptype=terrain&language=en-EN&key=xxx
#ggmap(map)
fin_map <- ggmap(map) + geom_point(data = new_cowpea, aes(Long_new, Lat_new, label = Accession.Name), colour = "red", alpha = 0.3)
## Warning: Ignoring unknown aesthetics: label
fin_map <- fin_map + xlab("Longitude") + ylab("Latitude")
fin_map
## Warning: Removed 3 rows containing missing values (geom_point).
for interactive map - see code below:
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggmap':
##
## wind
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
ggplotly(fin_map)