r语言批量绘制shp数据图
最近,我碰到了Stian Haklev撰写的一篇出色的文章,他描述了他希望从R入手起就被告知的事情 ,其中之一就是用我认为应该尝试的代码来清理所有数据 。
我的目标是使原始数据完全不变,并进行代码中的所有转换,这些转换可以随时重新运行。
在编写脚本时,我经常跳来跳去,有选择地执行单独的行或代码块,运行命令来检查REPL中的数据(read-evaluate-print-loop,其中每个命令都在您执行后立即执行)键入enter,在上方图片的右侧窗格中),等等。
但是我尝试确保完成后,脚本本身可以运行。
我认为Google趋势数据集非常有趣,因为它为您提供了CSV,其中包含几个不同的数据位,而我只对“随着时间的兴趣”感兴趣。
自动化CSV文件的下载并不是一件容易的事,所以我手动进行了一些操作,然后自动执行了所有操作。
第一步是读取CSV文件并浏览一些行以查看其中包含的内容:
> library(dplyr)
> googleTrends = read.csv("/Users/markneedham/Downloads/report.csv", row.names=NULL)
> googleTrends %>% head()
## row.names Web.Search.interest..neo4j
## 1 Worldwide; 2004 - present
## 2 Interest over time
## 3 Week neo4j
## 4 2004-01-04 - 2004-01-10 0
## 5 2004-01-11 - 2004-01-17 0
## 6 2004-01-18 - 2004-01-24 0
> googleTrends %>% sample_n(10)
## row.names Web.Search.interest..neo4j
## 109 2006-01-08 - 2006-01-14 0
## 113 2006-02-05 - 2006-02-11 0
## 267 2009-01-18 - 2009-01-24 0
## 199 2007-09-30 - 2007-10-06 0
## 522 2013-12-08 - 2013-12-14 88
## 265 2009-01-04 - 2009-01-10 0
## 285 2009-05-24 - 2009-05-30 0
## 318 2010-01-10 - 2010-01-16 0
## 495 2013-06-02 - 2013-06-08 79
## 28 2004-06-20 - 2004-06-26 0
> googleTrends %>% tail()
## row.names