使用ggmap: Spatial Visualization with ggplot2, by David Kahle and Hadley Wickham中暴力犯罪的填充等高线图中的例子(链接文章中的图9),我想知道是否代替 .. level .. ,我如何能够显示每平方(1000)公里的平均暴力犯罪,对我而言,这将更容易解释。
以下是该文章代码的摘录:
require(ggmap)
violent_crimes <- subset(crime, offense != "auto theft" & offense != "theft" & offense != "burglary")
violent_crimes$offense <- factor(violent_crimes$offense, levels = c("robbery", "aggravated assault", "rape", "murder"))
# restrict to downtown
violent_crimes <- subset(violent_crimes, -95.39681 <= lon & lon <= -95.34188 & 29.73631 <= lat & lat <= 29.78400)
houston <- get_map("houston", zoom = 14)
HoustonMap <- ggmap(houston, legend = "topleft")
HoustonMap +
stat_density2d(
aes(x = lon, y = lat, fill = ..level.., alpha = ..level..),
size = 2, data = violent_crimes,
geom = "polygon"
) + guides(alpha=FALSE)