R语言绘制地图并标色-作业举例
更新时间:2023-10-01 06:01:01 阅读量: 综合文库 文档下载
- 用r语言绘制中国地图推荐度:
- 相关推荐
作业讲解 - 用R语言绘制犯罪率增长高于20%的美国州地图
A criminology student has collected data about the number of violent assaults in each of the US states in 2014 and 2015. For his upcoming seminar, he is interested in identifying the states in which there has been at least a 20% increase in assaults.
Please help this student by identifying the relevant states, presenting them in a list or table, and creating a map of the USA where the relevant states are colored in red. This will require finding a relevant R package and using it to plot the map.
For this question only, attach the R script as a separate file with your full name as the file name. The script should enable me to get from the original csv file to the final map. 数据样式:(名称US Assaults.csv)
最终呈现:
R Studio 代码:
### package to use ######################################## library(maps) library(mapproj)
### read raw data ######################################## data = read.csv(\ # head(data)
rate = (data$Assaults.2015 - data$Assaults.2014)/data$Assaults.2014 newdata = cbind(data, rate)
########################################################## statenames = as.character(newdata$State) rate = newdata$rate
## assign color to state################################## ratecol = ifelse(rate > 0.2, \
### Import state data from package \data(state)
########### Substract names for state data ################ mapnames = map(\ # mapnames
# 63 and some have : and remiander representing islands and disconnected regions
########### Remove the state names containing : and remainder ################################
mapnames.state = ifelse(regexpr(\< 0, mapnames, substr(mapnames, 1, regexpr(\
#### convert upper case to lower case to faciliate matching of names ######## statenames.lower = tolower(statenames) ########## assign color according to our data ################################################# cols <- ratecol[match(mapnames.state, statenames.lower)]
########## Map ####################################################### map(\title(\
正在阅读:
R语言绘制地图并标色-作业举例10-01
脑机接口论文03-17
Existence and uniqueness of solutions on bounded domains to a FitzHugh-Nagumo type elliptic05-31
新视野大学英语2_选词填空原文及答案07-17
损伤因子01-28
《施工现场消防安全技术规范》习题04-21
我是中网小球童作文1500字04-05
《辐射安全与防护培训》试题 - 医学04-15
泰勒公式在若干数学分支中的应用06-05
中小学德育工作会议讲话稿10-05
- 多层物业服务方案
- (审判实务)习惯法与少数民族地区民间纠纷解决问题(孙 潋)
- 人教版新课标六年级下册语文全册教案
- 词语打卡
- photoshop实习报告
- 钢结构设计原理综合测试2
- 2014年期末练习题
- 高中数学中的逆向思维解题方法探讨
- 名师原创 全国通用2014-2015学年高二寒假作业 政治(一)Word版
- 北航《建筑结构检测鉴定与加固》在线作业三
- XX县卫生监督所工程建设项目可行性研究报告
- 小学四年级观察作文经典评语
- 浅谈110KV变电站电气一次设计-程泉焱(1)
- 安全员考试题库
- 国家电网公司变电运维管理规定(试行)
- 义务教育课程标准稿征求意见提纲
- 教学秘书面试技巧
- 钢结构工程施工组织设计
- 水利工程概论论文
- 09届九年级数学第四次模拟试卷
- 绘制
- 举例
- 作业
- 语言
- 地图