I'm trying to add a second set of data, as geographic points, to a ggmap plot. I already have bathymetric/topographic data applied to the map using geom_contour
and geom_raster
functions. But every time I add the function geom_point
, I get this message:
"Discrete value supplied to continuous scale"
This is what my geographic coordinates data frame (Coords) looks like:
Long Lat Type
1 155.5910 19.93401 Not geo-referenced
2 155.4998 19.83302 Not geo-referenced
3 155.2000 19.52440 Not geo-referenced
4 155.6302 20.00934 Geo-referenced
5 155.6623 19.81197 Not geo-referenced
6 155.5619 19.88102 Geo-referenced
How I obtained the bathymetric data (NOT relevant to this question)
bathydata <- getNOAA.bathy(lon1 = -180, lon2 = -154.5, lat1 = 29.3, lat2 =7, resolution = 7, antimeridian=FALSE)
bathydata <- as.matrix(bathydata)
class(bathydata) <- "matrix"
result1<- as.data.frame(bathydata)
result2<- rownames_to_column(result1, var = "lon")
result3<- gather(result2, lat, value, -1)
finalBathy<- mutate_all(result3, list(as.numeric))
This is what my bathymetric data frame (finalBathy) looks like:
lon lat value
1 -179.9417 7.058333 -5697
2 -179.8252 7.058333 -5582
3 -179.7088 7.058333 -5322
4 -179.5924 7.058333 -5708
5 -179.4759 7.058333 -5791
6 -179.3595 7.058333 -5781
My code
baseArchipelago = get_map(location = c(-180, 7, -154.5, 29.3), zoom = 6, maptype = "terrain")
mapArchipelago <- ggmap(baseArchipelago)
MapRaster <- mapArchipelago
+ geom_raster(data = finalBathy, aes(x = lon, y = lat, fill = value))
+ geom_contour(data = finalBathy, aes(x = lon, y = lat, z = value),
bins = 8, colour = "darkslategray", lwd=0.25)
+ geom_point(data=Coords, aes(x = -Long, y = Lat, fill = Type, shape = Type), color = "black",
cex = 1.2, show.legend = FALSE)
+ scale_shape_manual(values = c(23, 23), labels = c("Point 1", "Point2"), name = NULL)
MapFinal <- MapRaster + coord_cartesian()
((Note: without coord_cartesian()
, I get the error message: "Error: geom_raster only works with Cartesian coordinates"))
If I remove fill=Type
from the aes argument in geom_point, the problem is solved and the points get mapped correctly:
But I need the points to be filled by their Type!
And if I add scale_fill_manual(values=c("red", "blue"), labels=c("Point 1", "Point 2"), name=NULL)
to the code, the points go away and I get the same message again: "Discrete value supplied to continuous scale"
geom_raster
. Why not map your aesthetic usingcolor
instead offill
ingeom_point
? – Z.Lin