3
votes

I'm using R to plot some coordinates on a map, using the the following code:

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)

When I run this code I get this warning:

Warning messages: 1: In min(x) : no non-missing arguments to min; returning Inf 2: In max(x) : no non-missing arguments to max; returning -Inf 3: In min(x) : no non-missing arguments to min; returning Inf 4: In max(x) : no non-missing arguments to max; returning -Inf

Then the code displays the coordinates but with no map in the background. I have looked around and this error has occurred for other people but the solutions I saw don't seem to be suitable for my specific problem. I am using a smaller, cleaned version of this dataset from kaggle that has no nulls or NA in the target longitudes and latitudes that I'm using and there are no NA's at all in it.

My data structure:

'data.frame':   13 obs. of  20 variables:
$ mission.id                 : int  1 2 3 4 5 6 7 8 9 10 ...
$ mission.date               : Factor w/ 1 level "15/08/1943": 1 1 1 1 1 1 1 
1 1 1 ...
$ theater.of.operations      : Factor w/ 4 levels "CBI","ETO","MTO",..: 3 4 
3 3 4 4 4 4 3 3 ...
$ country                    : Factor w/ 2 levels "GREAT BRITAIN",..: 2 2 2 
2 2 2 2 2 2 2 ...
$ air.force                  : Factor w/ 4 levels "10 AF","12 AF",..: 2 3 2 
2 3 3 3 3 2 2 ...
$ aircraft.series            : Factor w/ 4 levels "A36","B17","B24",..: 1 3 
1 1 3 3 3 2 1 1 ...
$ mission.type               : Factor w/ 4 levels "OBJECTIVE BOMBING",..: 4 
1 4 4 1 1 3 1 4 4 ...
$ takeoff.base               : Factor w/ 2 levels "PONTE OLIVO AIRFIELD",..: 
1 2 1 1 2 2 2 2 1 1 ...
$ takeoff.location           : Factor w/ 2 levels "SICILY","UNKNOWN": 1 2 1 
1 2 2 2 2 1 1 ...
$ target.id                  : Factor w/ 6 levels "16140","3735",..: 4 6 5 1 
6 6 6 6 3 1 ...
$ target.country             : Factor w/ 5 levels "BURMA","GERMANY",..: 3 4 
3 3 5 4 4 4 3 3 ...
$ target.city.or.area        : Factor w/ 10 levels "BERLIN","COSENZA",..: 10 
6 2 3 5 4 8 8 9 3 ...
$ target.type                : Factor w/ 5 levels "AIRDROME","CITY AREA",..: 
4 3 4 4 5 4 4 1 4 4 ...
$ target.industry            : Factor w/ 3 levels "ARMAMENT AND ORDNANCE 
PLANTS",..: 3 3 3 3 3 3 3 3 3 1 ...
$ target.priority            : int  9 1 9 9 1 1 1 1 9 9 ...
$ target.latitude            : num  38.22 -7.17 39.27 38.43 -1.12 ...
$ target.longitude           : num  15.4 147 16.2 15.9 103.9 ...
$ altitude..hundreds.of.feet.: int  139 44 139 139 60 35 70 40 139 139 ...
$ source.id                  : Factor w/ 9 levels "11287","11326",..: 9 8 9 
9 3 7 1 2 9 9 ...
$ bomb.type                  : Factor w/ 2 levels "HIGH EXPLOSIVES",..: 1 1 
1 1 1 1 1 1 1 1 ...
2
What line throws the error? The code doesn't involve either min or max explicitly.John Coleman
I get the error after the last four lines, yeah I was thinking maybe I have to include them somewhere but I don't know where I would do that.Niall
Your question is so far from being a minimal reproducible example that it is hard to say anything, really. Some function (and you haven't specified which, exactly) doesn't like some input that you feed it (and we don't know what the input is). Should we just guess what the problem is?John Coleman
Reading this might help: stackoverflow.com/q/5963269/4996248 .John Coleman
Since you aren't showing us your data - at least show the structure of your dataframe str(df) then setup your data.frame in a more appropriate manner e.g., df <- data.frame(lon = smalloperations$target.longitude, lat = smalloperations$target.latitude) See if there is a different data structure Any NULL values in your smalloperations data? If so you need to use mean(df$lon, na.rm=T). Or share your data and someone can likely address the question explicitly.B Williams

2 Answers

0
votes

zoom is an integer from 3-20 http://stat405.had.co.nz/ggmap.pdf you are using 1

-1
votes

There is no reproducible answer so I cant be sure. But there (probably) a solution in the hablar package. mean in R does not work well with NA, Inf. Adding the s function on lat and lon gives you:

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)