简化地图:从数据可视化到深入分析
1. 准备工作
在处理空间数据之前,需要确保相关的R包已经安装。以下代码可以帮助我们完成这个任务:
# make sure the packages for this chapter
# are installed, install if necessary
pkg <- c("ggplot2", "scales", "maptools",
"sp", "maps", "grid", "car" )
new.pkg <- pkg[!(pkg %in% installed.packages())]
if (length(new.pkg)) {
install.packages(new.pkg)
}
2. 创建简单散点图
我们可以将Symantec的经纬度数据视为x、y坐标,创建一个简单的散点图,以此揭开地图的神秘面纱。
# Load ggplot2 to create graphics
library(ggplot2)
# read the CSV with headers
za <- read.csv("data/zeroaccess.csv", header=T)
# create a ggplot instance with zeroaccess data
gg <- ggplot(data=za, aes(x=long, y=lat))
# add the points, set transparency to 1/40th
g
超级会员免费看
订阅专栏 解锁全文
904

被折叠的 条评论
为什么被折叠?



