我正在研究加拿大的简单人口密度图。我已经根据邮政编码和经/纬度人口数据在这里
我想改进绘图以显示随着点密度增加的颜色变化。这是我的代码:
library(maptools)
library(gdata)
library(RColorBrewer)
library(classInt)
library(maps)
library(ggplot2)
library(ggmap)
Canada <- get_map(location="Canada", zoom=3, maptype="terrain")
ggmap(Canada, extent="normal") + geom_point(data=PopDensity, aes(x=LONG,y=LAT,size=POPULATION),
alpha = 0.3)+scale_size_continuous(range=c(1,6))
Run Code Online (Sandbox Code Playgroud)
这产生了一个像

我真正想要的是一种使数据点保持相同大小的方法,但不是使点透明,而是根据点密度改变颜色。
我正在尝试从 R 脚本中的 API 调用访问 JSON 响应。API调用成功,我可以在控制台中查看JSON响应。但是,我无法从中访问任何数据。
示例代码段是:
require(httr)
target <- '#trump'
sentence<- 'Donald trump has a wonderful toupe, it really is quite stunning that a man can be so refined and elegant'
query <- url_encode(sentence)
target <- gsub('#', '', target)
endpoint <- "https://alchemy.p.mashape.com/text/TextGetTargetedSentiment?outputMode=json&target="
apiCall <- paste(endpoint, target, '&text=', query, sep = '')
resp <-GET(apiCall, add_headers("X-Mashape-Key" = sentimentKey, "Accept" = "application/json"))
stop_for_status(resp)
headers(resp)
str(content(resp))
content(resp, "text")
Run Code Online (Sandbox Code Playgroud)
我遵循了 CRAN(此处)的 httr 快速入门指南以及此堆栈中的示例。
不幸的是,我不断收到“content() 中未使用的参数‘文本’”或“不存在接受一类‘响应’的 content() 定义。有人有什么建议吗?PS 标题将打印,resp$content 将打印原始比特流