0
votes

I am trying to plot some latitude/longitude points on a map using ggmap and geom_point. I have done it before and not had any problems but this time it simply will not show. I have tried unlisting the data, tinkering with aes(), etc and nothing has worked. The output of point_map is only the Area_Map with no points. What am I missing here?

# Read in data from csv files. 
bearingDat <- read.csv('bearing_Data.csv', sep = ',')

lonlatDat <- read.csv('lonlat_Data.csv', sep = ',')

# Create vectors for data. 
bearing <- c(bearingDat[1])
longitude <- c(lonlatDat[2])
latitude <- c(lonlatDat[1])

# Install necessary packages.
#install.packages("ggmap", "rworldmap")
#library(ggmap)
#library(rworldmap)


# Acquire map of area. 
Area_Map <- ggmap(get_map(location = c(175.733095424,-39.278361404),
                               zoom = 18,
                               maptype = "satellite",
                               color = "color"
)
)


point_map <- Area_Map + geom_point(data = lonlatDat, 
                                        aes(x=longitude, y=latitude),
                                        col = "red", 
                                        size = 1,
                                        alpha = 0.5,
                                        na.rm = TRUE
)

point_map

And here is the first 10 values for longitude and latitude, respectively.

1   175.4404  39.15582
2   175.4404  39.22650
3   175.4404  39.22650
4   175.4404  39.22650
5   175.4404  39.22650
6   175.4404  39.22650
7   175.4404  39.22650
8   175.4404  39.22650
9   175.4403  39.42777
10  175.4403  39.42777
1
In addition to your sign error, your code to "Create vectors for data" is bad (not that you use those in your plots). If bearingDat is a data frame, then bearingDat[1] is a one-column data frame, as is c(bearingDat[1]). If you want a vector, use bearingDat[[1]]. (The c() is pointless in both cases). - Gregor Thomas
@Gregor Thank you for pointing that out. Haven't spent much time with R recently so I must have gotten some things mixed up. - wastelander

1 Answers

2
votes

Your map is at -39.278361404 and your points at 39.15582, they are on opposite sides of the world.

If you fix one or the other, then you may see something. My gut instinct tells me at they might still be outside the scope of your zoom level.

Try using:

calc_zoom(lon, lat, data, adjust = 0, f = 0.05)

to get a zoom level which shows the farthest point from your original map and you should be good to go.