我正在尝试将这些数据绘制在安大略省多伦多市的 ggmap 上。然而,我得到的只是一个准确的图例和一张带有花蕊图的空白地图。这是
这是我的数据:data
看起来像这样
head(test)
final Month_Yr X Y
2575548 5.699134 2018-12 -79.83759 43.28888
2575550 0.000000 2018-12 -79.58547 43.89921
2575552 0.000000 2018-12 -79.69059 43.87526
2575554 5.111695 2018-12 -79.88913 43.30200
2575555 2.818152 2018-12 -79.34186 43.65824
2575556 5.667874 2018-12 -79.83636 43.28887
这是我的工作流程:
library(data.table)
library(raster)
library(sf)
library(stars)
library(terra)
library(dplyr)
library(ggplot2)
library("ggmap")
library(RColorBrewer)
# library(brewerpal)
library(colorRamps)
library(colorspace)
# open libraries
library(tidyverse)
gtha <- c(left = -79.95306, bottom = 43.27577, right = -78.91296, top = 43.95626 )
get_stamenmap(gtha, maptype = "toner-lite",crop = FALSE) %>% ggmap() +
geom_tile(data = test , aes(x = X, y = Y, fill = final)) +
theme_void()
我做错了什么?我想以光栅链接图像结束。
问题是你是在连续的尺度上绘图。因此,瓷砖只是(无限小)小到可见。
要使瓷砖可见,请设置
width
和 height
或使用具有矩形形状的 geom_point
。
library(ggplot2)
library(ggmap)
#> ℹ Google's Terms of Service: <https://mapsplatform.google.com>
#> ℹ Please cite ggmap if you use it! Use `citation("ggmap")` for details.
gtha <- c(left = -79.95306, bottom = 43.27577, right = -78.91296, top = 43.95626)
map <- get_stamenmap(gtha, maptype = "toner-lite", crop = FALSE)
#> ℹ Map tiles by Stamen Design, under CC BY 3.0. Data by OpenStreetMap, under ODbL.
p <- ggmap(map) +
theme_void()
p +
geom_tile(data = test, aes(x = X, y = Y, fill = final), height = .1, width = .1)
p +
geom_point(data = test, aes(x = X, y = Y, fill = final), shape = 22)
数据
test <- structure(list(final = c(
5.699134, 0, 0, 5.111695, 2.818152,
5.667874
), Month_Yr = c(
"2018-12", "2018-12", "2018-12", "2018-12",
"2018-12", "2018-12"
), X = c(
-79.83759, -79.58547, -79.69059,
-79.88913, -79.34186, -79.83636
), Y = c(
43.28888, 43.89921, 43.87526,
43.302, 43.65824, 43.28887
)), class = "data.frame", row.names = c(
"2575548",
"2575550", "2575552", "2575554", "2575555", "2575556"
))