我有这样的代码和数据来绘制美国的一些位置:
library(sf)
library(tidyverse)
set.seed(123) # for reproducibility
Latitude = round(runif(5000, 31, 46), digits = 5)
Longitude = round(runif(5000, -120, -80), digits = 5)
df = data.frame(Latitude, Longitude)
world <- ne_countries(scale = "medium", returnclass = "sf")
usa = filter(world,admin =="United States of America")
# Plot
ggplot() +
geom_sf(data = usa, fill = "blue",color = "black",alpha=.9) +
coord_sf(
xlim = c(-119, -74),
ylim = c(22, 51),
default_crs = sf::st_crs(4326),
crs = st_crs("ESRI:102003"),
expand = TRUE,
lims_method = "box",
label_axes = list(
bottom = "E", top = "E",
left = "N", right = "N"
))+stat_density2d_filled(data = df, aes(x = Longitude, y = Latitude, fill=(..level..),
alpha = (..level..)), geom = "polygon")
输出如下:
我希望排除一些水平,如(0,0002,0004],和(0,0004,0006]。此外,我想手动着色的水平。我有这个代码scale_fill_manual(values = c("khaki1", "khaki2", "khaki2", "orange", "orange", "red", "red", "red", "red"))
,但想使用scale_fill_gradientn
和调色板的RColorBrewer包,如YlOrRd。
1条答案
按热度按时间qhhrdooz1#
我没有美国底图图层,但这是否做你想与你的密度层?
由reprex package(v2.0.1)于2023年1月31日创建