Open wcornwell opened 2 years ago
possibly start with Venn Diagram
some data wrangling to get to here: https://github.com/traitecoevo/australian_plant_endemism/blob/master/intermediate_data/country_counts.csv
country_dataset="https://raw.githubusercontent.com/traitecoevo/australian_plant_endemism/6e12021f3604d0ad20bc5c44c9c9e08c9cf1a668/intermediate_data/country_dataset.csv"
country_dataset<-read.csv(url(country_dataset))
View(country_dataset)
install.packages("cowplot", "ggplot2", "ggrepel",
"ggspatial", "sf", "rnaturalearth", "rnaturalearthdata")
library(ggplot2)
library(rnaturalearth)
library(rnaturalearthdata)
country_count = "https://raw.githubusercontent.com/traitecoevo/australian_plant_endemism/master/intermediate_data/country_counts.csv"
country_count<-read.csv(url(country_count))
View(country_count)
country_count <- ne_countries(scale = "medium", returnclass = "sf")
class(country_count)
ggplot(data = country_count) +
geom_sf()
ggplot(data = country_dataset) +
geom_sf(aes(fill = country_count, length(
country_dataset="https://raw.githubusercontent.com/traitecoevo/australian_plant_endemism/6e12021f3604d0ad20bc5c44c9c9e08c9cf1a668/intermediate_data/country_dataset.csv"
country_dataset<-read.csv(url(country_dataset))
View(country_dataset)
library(ggplot2)
library(rnaturalearth)
library(rnaturalearthdata)
library(tidyverse)
country_count_basic = "https://raw.githubusercontent.com/traitecoevo/australian_plant_endemism/master/intermediate_data/country_counts.csv"
country_count_basic<-read_csv(url(country_count_basic))
View(country_count_basic)
country_count_basic$name<-gsub("_"," ",country_count_basic$Country)
country_count_basic$name<-str_to_title(country_count_basic$name)
country_count <- ne_countries(scale = "medium", returnclass = "sf")
class(country_count)
cc<-left_join(country_count,country_count_basic)
ggplot(data = cc) +
geom_sf(aes(fill = `sum(presence)`),size=0.1)
successful map but needs to be cropped to oceania
##making a map with points and connections
install.packages("maps")
library(maps)
library(geosphere)
# No margin
par(mar=c(0,0,0,0))
# World map
map('world',
col="#f2f2f2", fill=TRUE, bg="white", lwd=0.05,
mar=rep(0,4),border=0, ylim=c(-80,80) )
# Dplyr for data wrangling and pipe function
library(dplyr)
# Cities
Sydney <- c(151, -34)
Hong_Kong <- c(114, 22)
Jakarta <- c(107, -6)
New_Guinea <- c(147, -9)
# Data frame
data <- rbind(Hong_Kong, Sydney, Jakarta, New_Guinea) %>%
as.data.frame()
colnames(data) <- c("long","lat")
# Show the cities on the map
map('world',
col="#f2f2f2", fill=TRUE, bg="white", lwd=0.05,
mar=rep(0,4),border=0, ylim=c(-80,80)
)
points(x=data$long, y=data$lat, col="slateblue", cex=2, pch=20)
# Load geosphere
install.packages("geosphere")
library(geosphere)
# Background map
map('world',
col="#f2f2f2", fill=TRUE, bg="white", lwd=0.05,
mar=rep(0,4),border=0, ylim=c(-80,80)
)
# Dot for cities
points(x=data$long, y=data$lat, col="slateblue", cex=1.5, pch=20)
# Compute the connection
inter <- gcIntermediate(Jakarta, Hong_Kong, n=50, addStartEnd=TRUE, breakAtDateLine=F)
# Show this connection
lines(inter, col="slateblue", lwd=2)
# conect
inter <- gcIntermediate(New_Guinea, Sydney, n=50, addStartEnd=TRUE, breakAtDateLine=F)
lines(inter, col="slateblue", lwd=2)
# A function to plot connections
plot_my_connection=function( dep_lon, dep_lat, arr_lon, arr_lat, ...){
inter <- gcIntermediate(c(dep_lon, dep_lat), c(arr_lon, arr_lat), n=50, addStartEnd=TRUE, breakAtDateLine=F)
inter=data.frame(inter)
diff_of_lon=abs(dep_lon) + abs(arr_lon)
if(diff_of_lon > 180){
lines(subset(inter, lon>=0), ...)
lines(subset(inter, lon<0), ...)
}else{
lines(inter, ...)
}
}
# Background map
map('world',col="#f2f2f2", fill=TRUE, bg="white", lwd=0.05,mar=rep(0,4),border=0, ylim=c(-80,80) )
# Circles for cities
points(x=data$long, y=data$lat, col="slateblue", cex=1.5, pch=20)
# Connections
plot_my_connection(New_Guinea[1], New_Guinea[2], Sydney[1], Sydney[2], col="slateblue", lwd=2)
plot_my_connection(Jakarta[1], Jakarta[2], Sydney[1], Sydney[2], col="slateblue", lwd=2)
plot_my_connection(Jakarta[1], Jakarta[2], New_Guinea[1], New_Guinea[2], col="slateblue", lwd=2)
plot_my_connection(Hong_Kong[1], Hong_Kong[2], Jakarta[1], Jakarta[2], col="slateblue", lwd=2)
#creating a cropped map of Oceania
install.packages("ggplot2")
install.packages("sf")
install.packages("rnaturalearth")
library(ggplot2)
library(sf)
library(rnaturalearth)
worldmap <- ne_countries(scale = 'medium', type = 'map_units',
returnclass = 'sf')
# have a look at these two columns only
head(worldmap[c('name', 'continent')])
#just australia
ggplot() + geom_sf(data = worldmap) + theme_bw()
Australia <- worldmap[worldmap$name == 'Australia',]
ggplot() + geom_sf(data = Australia) + theme_bw()
#Oceania
Oceania <- worldmap[worldmap$continent == 'Oceania',]
ggplot() + geom_sf(data = Oceania) + theme_bw()
#crop. xmin is longitude and ymin/max is lat
oceania_cropped <- st_crop(worldmap, xmin = -180, xmax = 60,
ymin = -54, ymax = 12)
ggplot() + geom_sf(data = oceania_cropped) + theme_bw()
# oceania cropped
oceania.c <- ggplot() + geom_sf(data = worldmap) +
coord_sf(xlim = c(25, 180), ylim = c(-54, 50), expand = FALSE) +
theme_bw()
#trying to add points and connections to oceania cropped
# No margin
par(mar=c(0,0,0,0))
# World map
map('world',
col="#f2f2f2", fill=TRUE, bg="white", lwd=0.05,
mar=rep(0,4),border=0, ylim=c(-80,80) )
# Dplyr for data wrangling and pipe function
library(dplyr)
# Cities
Sydney <- c(151, -34)
Hong_Kong <- c(114, 22)
Jakarta <- c(107, -6)
New_Guinea <- c(147, -9)
# Data frame
data <- rbind(Hong_Kong, Sydney, Jakarta, New_Guinea) %>%
as.data.frame()
colnames(data) <- c("long","lat")
# Show the cities on the map
map('world',
col="#f2f2f2", fill=TRUE, bg="white", lwd=0.05,
mar=rep(0,4),border=0, ylim=c(-80,80)
)
points(x=data$long, y=data$lat, col="slateblue", cex=2, pch=20)
# Load geosphere
# Background map
map('world',
col="#f2f2f2", fill=TRUE, bg="white", lwd=0.05,
mar=rep(0,4),border=0, ylim=c(-80,80)
)
# Dot for cities
points(x=data$long, y=data$lat, col="slateblue", cex=1.5, pch=20)
# Compute the connection
inter <- gcIntermediate(Jakarta, Hong_Kong, n=50, addStartEnd=TRUE, breakAtDateLine=F)
# Show this connection
lines(inter, col="slateblue", lwd=2)
# conect
inter <- gcIntermediate(New_Guinea, Sydney, n=50, addStartEnd=TRUE, breakAtDateLine=F)
lines(inter, col="slateblue", lwd=2)
# A function to plot connections
plot_my_connection=function( dep_lon, dep_lat, arr_lon, arr_lat, ...){
inter <- gcIntermediate(c(dep_lon, dep_lat), c(arr_lon, arr_lat), n=50, addStartEnd=TRUE, breakAtDateLine=F)
inter=data.frame(inter)
diff_of_lon=abs(dep_lon) + abs(arr_lon)
if(diff_of_lon > 180){
lines(subset(inter, lon>=0), ...)
lines(subset(inter, lon<0), ...)
}else{
lines(inter, ...)
}
}
# Background map
map('world',col="#f2f2f2", fill=TRUE, bg="white", lwd=0.05,mar=rep(0,4),border=0, ylim=c(-80,80) )
# Circles for cities
points(x=data$long, y=data$lat, col="slateblue", cex=1.5, pch=20)
# Connections
plot_my_connection(New_Guinea[1], New_Guinea[2], Sydney[1], Sydney[2], col="slateblue", lwd=2)
plot_my_connection(Jakarta[1], Jakarta[2], Sydney[1], Sydney[2], col="slateblue", lwd=2)
plot_my_connection(Jakarta[1], Jakarta[2], New_Guinea[1], New_Guinea[2], col="slateblue", lwd=2)
plot_my_connection(Hong_Kong[1], Hong_Kong[2], Jakarta[1], Jakarta[2], col="slateblue", lwd=2)
map('world',
col="#f2f2f2", fill=TRUE, bg="white", lwd=0.05,
mar=rep(0,4),border=0, ylim=c(-54,12) ,xlim=c(60,180))
)
The idea is to show the shared ranges between Australia and other countries
for example
this is drawing to start with and then looking for the way to do this in R.