【发布时间】:2015-12-02 08:56:10
【问题描述】:
我正在尝试复制以下脚本:San Francisco Crime Classification
这是我的代码:
library(dplyr)
library(ggmap)
library(ggplot2)
library(readr)
library(rjson)
library(RCurl)
library(RJSONIO)
library(jsonlite)
train=jsonlite::fromJSON("/home/felipe/Templates/Archivo de prueba/databritanica.json")
counts <- summarise(group_by(train, Crime_type), Counts=length(Crime_type))
#counts <- counts[order(-counts$Crime_type),]
# This removes the "Other Offenses" category
top12 <- train[train$Crime_type %in% counts$Crime_type[c(1,3:13)],]
map<-get_map(location=c(lon = -2.747770, lat = 53.389499) ,zoom=12,source="osm")
p <- ggmap(map) +
geom_point(data=top12, aes(x=Longitude, y=Latitude, color=factor(Crime_type)), alpha=0.05) +
guides(colour = guide_legend(override.aes = list(alpha=1.0, size=6.0),
title="Type of Crime")) +
scale_colour_brewer(type="qual",palette="Paired") +
ggtitle("Top Crimes in Britain") +
theme_light(base_size=20) +
theme(axis.line=element_blank(),
axis.text.x=element_blank(),
axis.text.y=element_blank(),
axis.ticks=element_blank(),
axis.title.x=element_blank(),
axis.title.y=element_blank())
ggsave("united kingdom_top_crimes_map.png", p, width=14, height=10, units="in")
我正在从 JSON 文件中读取数据,并尝试根据数据在地图上打印点。每个点都是一种犯罪类型,每个点的位置取决于两个参数:经度和纬度。
有什么问题?这些点没有被打印。该脚本会生成一个没有应该显示的点的新地图。
有什么想法吗??
JSON 文件中包含的数据示例如下:
[
{"Month":"2014-05","Longitude":-2.747770,"Latitude":53.389499,"Location":"On or near Cronton Road","LSOA_name":"Halton 001B","Crime_type":"Other theft"},
{"Month":"2014-05","Longitude":-2.799099,"Latitude":53.354676,"Location":"On or near Old Higher Road","LSOA_name":"Halton 008B","Crime_type":"Anti-social behaviour"},
{"Month":"2014-05","Longitude":-2.804451,"Latitude":53.352456,"Location":"On or near Higher Road","LSOA_name":"Halton 008B","Crime_type":"Anti-social behaviour"}
]
【问题讨论】:
-
您是否测试过更高的 alpha 值? 0.05 的 alpha 使点几乎透明,即使没有背景贴图我也几乎看不到。
-
您还需要在所有的
library()电话中冷静下来。看起来您需要显式调用的唯一包是ggplot2、ggmap、dplyr和jsonlite。