首页 文章

R:ggmap:在plottinng中包含缺失值(geom_point)但在映射范围内没有NAs值/值

提问于
浏览
1

我正在使用ggmap在 Map 上绘制一些点 . 这是错误消息:

Removed 10 rows containing missing values (geom_point).

这是我的代码:

library(ggmaps)
    library(maps)
    library(DataComputing)
    map <- get_map(location='san francisco', zoom=12, maptype = 'terrain', source = 'google', color = 'color')
    ggmap(map) %>%
    + geom_point(aes(x=longitude, y=latitude, colour = as.numeric(total)), data=district_crimes) %>%
    + scale_color_gradient(low='beige', high='blue')

Data frame

Proof that longitude and latitude are numeric.

怎么得分积分?谢谢 .

1 回答

  • 2

    @timfaber的建议是对的 . 经度位于x轴上,纬度位于y轴上,如下图中的轴标签所示:

    ggmap(map)
    

    enter image description here

    因此,在 Map 上绘制点的正确方法是:

    ggmap(map) +
     geom_point(aes(x=latitude, y=longitude, colour = as.numeric(total)), 
       size=4, data=district_crimes) +
    scale_color_gradient(low='blue', high='red')
    

    enter image description here

相关问题