R:ggmap:绘图时包含缺失值(geom_point)但在 data.frame 中未找到 NA 值

R: ggmap: containing missing values (geom_point) when plottinng but no NAs values found in data.frame

我正在使用 ggmap 包在地图上绘制一些点。

问题是我收到消息:"Removed 12 rows containing missing values (geom_point)".

但我没有任何 NA。我查看了数据,并使用了:

sum(is.na(limanov2)) #Gives 0

证明它。

这是我的代码:

library(maps)
library(ggmap)

lima <- get_map(location = "lima", zoom = 11)

    ggmap(lima) + geom_point(data = limanov2, aes(x = LONGITUD , y = LATITUD, color = TOTALES,
                                                      size = TOTALES)) +
            scale_color_gradient(low = "yellow", high = "red")

我的数据:

structure(list(DISTRITO = c("SAN JUAN DE LURIGANCHO", "CALLAO", 
"LOS OLIVOS", "ATE VITARTE", "LIMA CERCADO", "SAN MARTÍN", "SANTIAGO DE SURCO", 
"CHORILLOS", "COMAS", "INDEPENDENCIA", "EL AGUSTINO", "LA VICTORIA", 
"SAN JUAN DE MIRAFLORES", "VILLA EL SALVADOR", "S. MIGUEL", "CARABAYLLO", 
"MIRAFLORES", "PTE. PIEDRA", "SAN BORJA", "VENTANILLA", "SURQUILLO", 
"BREÑA", "ANCÓN", "EL RIMAC", "BARRANCO", "LA MOLINA", "SAN LUIS", 
"STA. ANITA", "LURIGANCHO", "P. LIBRE", "MAGDALENA", "LA PERLA", 
"CHACLACAYO", "SAN ISIDRO", "J. MARÍA", "BELLAVISTA", "LINCE", 
"C. DE LA LEGUA", "CIENEGUILLA", "STA.ROSA", "LURÍN", "PTA.NEGRA", 
"PUCUSANA", "LA PUNTA", "PTA. HERMOSA", "PACHACAMAC", "SAN BARTOLO", 
"SANTA MARÍA"), TOTALES = c(861L, 696L, 696L, 642L, 516L, 479L, 
442L, 378L, 371L, 368L, 361L, 333L, 325L, 291L, 282L, 251L, 239L, 
223L, 196L, 193L, 188L, 185L, 174L, 161L, 138L, 134L, 128L, 119L, 
115L, 105L, 67L, 65L, 63L, 58L, 56L, 45L, 38L, 23L, 23L, 11L, 
8L, 6L, 5L, 3L, 3L, 2L, 0L, 0L), HOMICIDIOS = c(1L, 7L, 0L, 1L, 
2L, 0L, 0L, 1L, 7L, 4L, 4L, 4L, 0L, 0L, 0L, 2L, 0L, 1L, 0L, 7L, 
0L, 0L, 0L, 4L, 0L, 0L, 2L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
1L, 1L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), LESIONES = c(100L, 
72L, 61L, 43L, 44L, 8L, 10L, 15L, 44L, 40L, 50L, 15L, 52L, 28L, 
7L, 33L, 15L, 27L, 3L, 21L, 7L, 36L, 33L, 19L, 14L, 1L, 8L, 6L, 
16L, 4L, 4L, 9L, 1L, 2L, 9L, 5L, 2L, 5L, 7L, 1L, 0L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L), VIO..DE.LA.LIBERTAD.PERSONAL = c(0L, 7L, 
6L, 5L, 6L, 1L, 1L, 0L, 3L, 1L, 2L, 0L, 2L, 0L, 1L, 0L, 1L, 1L, 
0L, 1L, 1L, 0L, 3L, 1L, 1L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 0L, 1L, 
0L, 0L, 0L, 2L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), VIO..DE.LA.LIBERTAD.SEXUAL = c(56L, 
14L, 12L, 15L, 7L, 10L, 2L, 9L, 11L, 13L, 8L, 9L, 7L, 14L, 4L, 
15L, 4L, 12L, 2L, 17L, 7L, 3L, 4L, 12L, 2L, 1L, 5L, 3L, 11L, 
4L, 1L, 2L, 0L, 2L, 0L, 3L, 0L, 2L, 2L, 0L, 4L, 0L, 0L, 0L, 0L, 
0L, 0L, 0L), HURTO.SIMPLE.Y.AGRAVADO = c(217L, 203L, 296L, 230L, 
260L, 167L, 226L, 217L, 130L, 117L, 154L, 133L, 121L, 46L, 163L, 
72L, 161L, 84L, 119L, 69L, 120L, 64L, 19L, 21L, 57L, 44L, 39L, 
2L, 48L, 60L, 30L, 19L, 48L, 41L, 25L, 19L, 27L, 7L, 11L, 9L, 
0L, 6L, 0L, 2L, 3L, 1L, 0L, 0L), ROBO.SIMPLE.Y.AGRAVADO = c(460L, 
289L, 308L, 344L, 186L, 277L, 198L, 130L, 165L, 184L, 137L, 149L, 
134L, 188L, 104L, 126L, 58L, 96L, 72L, 64L, 51L, 77L, 115L, 76L, 
64L, 88L, 73L, 108L, 40L, 36L, 30L, 32L, 14L, 12L, 22L, 12L, 
8L, 6L, 3L, 1L, 3L, 0L, 2L, 1L, 0L, 1L, 0L, 0L), MICRO.COM.DE.DROGAS = c(26L, 
100L, 13L, 3L, 10L, 15L, 5L, 5L, 11L, 8L, 3L, 23L, 9L, 15L, 3L, 
3L, 0L, 2L, 0L, 8L, 2L, 5L, 0L, 28L, 0L, 0L, 1L, 0L, 0L, 0L, 
2L, 2L, 0L, 0L, 0L, 6L, 0L, 0L, 0L, 0L, 0L, 0L, 3L, 0L, 0L, 0L, 
0L, 0L), TENENCIA.ILEGAL.DE.ARMAS = c(1L, 4L, 0L, 1L, 1L, 1L, 
0L, 1L, 0L, 1L, 3L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 6L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), LONGITUD = c(-77, -77.12, 
-77.08, -76.89, -77.04, -77.09, -76.99, -77.01, -77.05, -77.05, 
-77, -77.02, -76.97, -76.94, -77.09, -76.99, -77.03, -77.08, 
-77, -77.13, -77.01, -77.05, -77.11, -76.7, -77.02, -76.92, -77, 
-76.96, -76.86, -77.06, -77.07, -77.12, -76.76, -77.03, -77.05, 
-77.11, -77.04, -77.09, -76.78, -77.16, -76.81, -76.73, -76.77, 
-77.16, -76.76, -76.83, -76.73, -76.77), LATITUD = c(-11.99, 
-12.04, -11.97, -12.04, -12.06, -12, -12.16, -12.2, -11.93, -11.99, 
-12.04, -12.08, -12.16, -12.23, -12.08, -11.79, -12.12, -11.88, 
-12.1, -11.89, -12.11, -12.06, -11.69, -11.94, -12.15, -12.09, 
-12.08, -12.04, -11.98, -12.08, -12.09, -12.07, -11.99, -12.1, 
-12.08, -12.06, -12.09, -12.04, -12.07, -11.81, -12.24, -12.32, 
-12.47, -12.07, -12.28, -12.18, -12.38, -12.42)), class = c("tbl_df", 
"tbl", "data.frame"), row.names = c(NA, -48L), .Names = c("DISTRITO", 
"TOTALES", "HOMICIDIOS", "LESIONES", "VIO..DE.LA.LIBERTAD.PERSONAL", 
"VIO..DE.LA.LIBERTAD.SEXUAL", "HURTO.SIMPLE.Y.AGRAVADO", "ROBO.SIMPLE.Y.AGRAVADO", 
"MICRO.COM.DE.DROGAS", "TENENCIA.ILEGAL.DE.ARMAS", "LONGITUD", 
"LATITUD"))

您的值超出了基础地图缩放范围...尝试更改您的缩放参数。

library(maps)
library(ggmap)

lima <- get_map(location = "lima", zoom = 10)

ggmap(lima) + 
  geom_point(data = limanov2, 
             aes(x = LONGITUD , y = LATITUD, 
                 color = TOTALES, size = TOTALES)) +
  scale_color_gradient(low = "yellow", high = "red")