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
bearingDatis a data frame, thenbearingDat[1]is a one-column data frame, as isc(bearingDat[1]). If you want a vector, usebearingDat[[1]]. (Thec()is pointless in both cases). - Gregor Thomas