我正在尝试将另一组数据(作为地理点)添加到ggmap图中。我已经使用geom_contour
和geom_raster
函数将测深/地形数据应用于地图。但是每次添加函数geom_point
时,都会收到以下消息:
“离散值提供给连续刻度”
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
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))
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
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()
(((注意:如果没有coord_cartesian()
,我会收到错误消息:“错误:geom_raster仅适用于笛卡尔坐标”)
如果我从geom_point的aes参数中删除fill=Type
,则问题得到解决,并且点已正确映射:
但是我需要用它们的类型填充点!
如果我在代码中添加scale_fill_manual(values=c("red", "blue"), labels=c("Point 1", "Point 2"), name=NULL)
,这些点消失了,并且我再次收到相同的消息:“为连续刻度提供离散值”
答案 0 :(得分:0)
您可以添加其他离散量表来表示离散变量:
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, color = Type, shape = ype),
cex = 1.2, show.legend = FALSE) +
scale_discrete_manual(aesthetics = c("colour"),
values = c("red", "yellow"),
labels = c("Point 1","Point2"),
name = NULL) +
scale_discrete_manual(aesthetics = c("shape"),
values = 16:17,
labels = c("Point 1","Point2"),
name = NULL)
哪个给
它能回答您的问题吗?