输入数据示例
# 读取数据文件
mydata <- read.table("gzwj.csv", header = TRUE, sep = ",")
visit.x <- mydata$Longitude
visit.y <- mydata$Latitude
# 载入所需的库
library(ggplot2)
library(ggmap)
library(sp)
library(maptools)
library(maps)
# 创建地图对象
mp <- NULL
mapworld <- borders("world", colour = "gray50", fill = "white")
mp <- ggplot() + mapworld + coord_cartesian(xlim = c(-180, 180), ylim = c(-90, 90))
# 创建地图可视化图层
mp2 <- mp + geom_point(aes(x = visit.x, y = visit.y, color = log2(Number)),
data = mydata,
size = 2,
alpha = 0.8) +
scale_color_gradient(low = "lightgreen", high = "darkgreen",
guide = guide_colorbar(title = "log2(样本数量)")) +
ggtitle("样本收集情况") +
theme(plot.title = element_text(size = 25, color = "red", face = "italic")) +
theme_grey(base_size = 32) +
theme(legend.position = "bottom")
# 保存地图可视化结果为PDF文件
ggsave("map_plot.pdf", plot = mp2, width = 12, height = 8)
网友评论