Mapping points by coordinates
Jul. 2nd, 2025 11:06 am![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
Some R code for mapping collection points from the table of coordinates:
install.packages("maps")
library(maps)
locations <- read.csv("locations.csv", header=TRUE)
View(locations)
world_map <- map_data("world")
#Creat a base plot with gpplot2
p <- ggplot() + coord_fixed() +
xlab("") + ylab("")
p
#Add map to base plot
base_world_messy <- p + geom_polygon(data=world_map, aes(x=long, y=lat, group=group),
colour="darkgray", fill="gray")
base_world_messy
#Strip the map down so it looks super clean (and beautiful!)
cleanup <-
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_rect(fill = 'white', colour = 'white'),
axis.line = element_line(colour = "white"), legend.position="none",
axis.ticks=element_blank(), axis.text.x=element_blank(),
axis.text.y=element_blank())
base_world <- base_world_messy + cleanup
base_world
map_data <-
base_world +
geom_point(data=locations,
aes(x=decimalLongitude, y=decimalLatitude), colour="black",
fill="lightblue",pch=21, size=2, alpha=I(0.7))
map_data
install.packages("maps")
library(maps)
locations <- read.csv("locations.csv", header=TRUE)
View(locations)
world_map <- map_data("world")
#Creat a base plot with gpplot2
p <- ggplot() + coord_fixed() +
xlab("") + ylab("")
p
#Add map to base plot
base_world_messy <- p + geom_polygon(data=world_map, aes(x=long, y=lat, group=group),
colour="darkgray", fill="gray")
base_world_messy
#Strip the map down so it looks super clean (and beautiful!)
cleanup <-
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_rect(fill = 'white', colour = 'white'),
axis.line = element_line(colour = "white"), legend.position="none",
axis.ticks=element_blank(), axis.text.x=element_blank(),
axis.text.y=element_blank())
base_world <- base_world_messy + cleanup
base_world
map_data <-
base_world +
geom_point(data=locations,
aes(x=decimalLongitude, y=decimalLatitude), colour="black",
fill="lightblue",pch=21, size=2, alpha=I(0.7))
map_data