min和max没有非缺失参数

时间:2017-04-08 15:37:54

标签: r ggplot2 ggmap

我正在使用R在地图上绘制一些坐标,使用以下代码:

create table eas_citizen_text_info (
    UID int(12) Primary key,
    Gender char(15),
    First_name varchar(30),
    Middle_name varchar(30),
    Last_name varchar(30),
    DOB date Not null,
    Age int(3),
    Caste varchar(30),
    Martial_status varchar(15),
    Address varchar(255),
    House_No_Bldg_Apt varchar(75),
    Street_Road_Lane varchar(75),
    Landmark varchar(75),
    Area_locality_sector varchar(75),
    Village_Town_City varchar(75),
    Post_office varchar(75),
    District varchar(25),
    Sub_district varchar(25),
    Pincode int(12),
    State varchar(30),
    Father_name varchar(200),
    Mother_name varchar(200),
    Guardian_name varchar(200)
);

当我运行此代码时,我收到此警告:

  

警告讯息:   1:在min(x)中:min没有非缺失参数;返回Inf   2:在max(x)中:max没有非缺失参数;返回-Inf   3:在min(x)中:min没有非缺失参数;返回Inf   4:在max(x)中:max没有非缺失参数;返回-Inf

然后代码显示坐标,但背景中没有地图。我环顾四周,其他人发生了这个错误,但我看到的解决方案似乎不适合我的具体问题。 我正在使用较小的清洁版this dataset from kaggle,它在我正在使用的目标经度和纬度中没有空值或NA,并且根本没有NA。

我的数据结构:

library(ggplot2)
library(ggmap)

smalloperations <- read.csv("S:/smalloperations.csv", na.strings=c("","NA"))

lon <- c(smalloperations$target.longitude)
lat <- c(smalloperations$target.latitude)
df <- as.data.frame(cbind(lon,lat))

# getting the map
mapgilbert <- get_map(location = c(lon = mean(df$lon), lat = mean(df$lat)), 
zoom = 1, maptype = "satellite", scale = 2)

# plotting the map with some points on it
ggmap(mapgilbert) +
geom_point(data = df, aes(x = lon, y = lat, fill = "red", alpha = 0.8), size 
= 5, shape = 21) +
guides(fill=FALSE, alpha=FALSE, size=FALSE)

2 个答案:

答案 0 :(得分:2)

zoom是3-20 http://stat405.had.co.nz/ggmap.pdf的整数,您使用1

答案 1 :(得分:-1)

没有可重复的答案,所以我不能确定。但是(可能)在hablar包装中有解决方案。 R中的均值不适用于NA,Inf。在lat和lon上添加s函数可以为您提供:

library(ggplot2)
library(ggmap)
library(hablar)

smalloperations <- read.csv("S:/smalloperations.csv", na.strings=c("","NA"))

lon <- c(smalloperations$target.longitude)
lat <- c(smalloperations$target.latitude)
df <- as.data.frame(cbind(lon,lat))

# getting the map
mapgilbert <- get_map(location = c(lon = mean(s(df$lon)), lat = mean(s(df$lat))), 
zoom = 1, maptype = "satellite", scale = 2)

# plotting the map with some points on it
ggmap(mapgilbert) +
geom_point(data = df, aes(x = lon, y = lat, fill = "red", alpha = 0.8), size 
= 5, shape = 21) +
guides(fill=FALSE, alpha=FALSE, size=FALSE)