我有以下代码:
library(ggrepel)
library(ggOceanMaps)
library(ggspatial)
library(readr)
map <- basemap(c(-180, 180, -90, 90), bathymetry = TRUE)+
ggspatial::geom_spatial_point(
data = daten_neu, aes(x = as.numeric(Longitude), y = as.numeric(Latitude), color = as.numeric(Neogloboquadrina_pachyderma...35))
)
print(map)
使用这些数据:
Latitude Longitude Neogloboquadrina_pachyderma...35
<chr> <chr> <chr>
1 8.983 51.733 1
2 44.3498 -30.267 8
3 50.9332 -41.75 602
4 36.1333 -68.9167 1
5 35.7833 -68.9333 1
6 37.65 -72.95 62
7 35.7667 -69.0833 1
8 39.1332 -42.65 2
9 5.2833 -17.0667 1
10 3.65 -18.3 14
但是,我有几个问题无法通过网络搜索得到答案。 1.更改as.numeric(),以便我可以将范围设置为300,并且其上方的所有内容仅显示为顶部颜色
图例可以通过
scale_xxx_xxx
控制。当您绘制 color
美学时,它是 scale_color_xxx
;当您有一个连续变量时,它是 scale_color_continuous
。但是,当您想要从红色到蓝色的渐变时,最好切换到 scale_color_gradient
。
接下来,虽然您可以重新编码数据,但对于高于阈值的点具有相同颜色的一个选项是设置比例限制并使用
oob = scales::oob_squish
:
library(ggOceanMaps)
library(ggspatial)
basemap(c(-180, 180, -90, 90), bathymetry = TRUE) +
ggspatial::geom_spatial_point(
data = daten_neu, aes(
x = as.numeric(Longitude),
y = as.numeric(Latitude),
color = as.numeric(Neogloboquadrina_pachyderma...35)
)
) +
scale_color_gradient(
name = "Neogloboquadrina pachyderma",
breaks = seq(0, 300, 100),
labels = c(seq(0, 250, 100), "300 and more"),
low = "darkred", high = "darkblue",
limits = c(NA, 300),
oob = scales::oob_squish
)
数据
# run e.g. dput(head(date_neu, 10))
daten_neu <- structure(list(Latitude = c(
8.983, 44.3498, 50.9332, 36.1333,
35.7833, 37.65, 35.7667, 39.1332, 5.2833, 3.65
), Longitude = c(
51.733,
-30.267, -41.75, -68.9167, -68.9333, -72.95, -69.0833, -42.65,
-17.0667, -18.3
), Neogloboquadrina_pachyderma...35 = c(
1L, 8L,
602L, 1L, 1L, 62L, 1L, 2L, 1L, 14L
)), class = "data.frame", row.names = c(
"1",
"2", "3", "4", "5", "6", "7", "8", "9", "10"
))