R 中的纹理贴图
Texture map in R
我想为美国经纬度不同的点创建alpha值的纹理贴图。
目前,我最多只能使用此代码生成以下图像:
map('state', plot = TRUE, fill = FALSE, col = palette())
points(Fit_Gamma_January$longitud,Fit_Gamma_January$latitud, col="red", cex=1.5)
我的数据是:
dput(Fit_Gamma_January)
structure(list(latitud = c(51.25, 51.25, 51.25, 51.25, 51.25,
51.25, 51.25, 51.25, 51.25, 51.25, 51.25, 51.25, 51.25, 51.25,
51.25, 51.25, 51.25, 51.25, 51.25, 51.25, 51.25, 51.25, 51.25,
51.25, 51.25, 28.75, 28.75, 28.75, 28.75, 28.75, 28.75, 28.75,
28.75, 28.75, 28.75, 28.75, 28.75, 28.75, 28.75, 28.75, 28.75,
28.75, 28.75, 28.75, 28.75, 28.75, 28.75, 28.75, 28.75, 28.75,
26.25, 26.25, 26.25, 26.25, 26.25, 26.25, 26.25, 26.25, 26.25,
26.25, 26.25, 26.25, 26.25, 26.25, 26.25, 26.25, 26.25, 26.25,
26.25, 26.25, 26.25, 26.25, 26.25, 26.25, 26.25, 23.75, 23.75,
23.75, 23.75, 23.75, 23.75, 23.75, 23.75, 23.75, 23.75, 23.75,
23.75, 23.75, 23.75, 23.75, 23.75, 23.75, 23.75, 23.75, 23.75,
23.75, 23.75, 23.75, 23.75, 23.75, 48.75, 48.75, 48.75, 48.75,
48.75, 48.75, 48.75, 48.75, 48.75, 48.75, 48.75, 48.75, 48.75,
48.75, 48.75, 48.75, 48.75, 48.75, 48.75, 48.75, 48.75, 48.75,
48.75, 48.75, 48.75, 46.25, 46.25, 46.25, 46.25, 46.25, 46.25,
46.25, 46.25, 46.25, 46.25, 46.25, 46.25, 46.25, 46.25, 46.25,
46.25, 46.25, 46.25, 46.25, 46.25, 46.25, 46.25, 46.25, 46.25,
46.25, 43.75, 43.75, 43.75, 43.75, 43.75, 43.75, 43.75, 43.75,
43.75, 43.75, 43.75, 43.75, 43.75, 43.75, 43.75, 43.75, 43.75,
43.75, 43.75, 43.75, 43.75, 43.75, 43.75, 43.75, 43.75, 41.25,
41.25, 41.25, 41.25, 41.25, 41.25, 41.25, 41.25, 41.25, 41.25,
41.25, 41.25, 41.25, 41.25, 41.25, 41.25, 41.25, 41.25, 41.25,
41.25, 41.25, 41.25, 41.25, 41.25, 41.25, 38.75, 38.75, 38.75,
38.75, 38.75, 38.75, 38.75, 38.75, 38.75, 38.75, 38.75, 38.75,
38.75, 38.75, 38.75, 38.75, 38.75, 38.75, 38.75, 38.75, 38.75,
38.75, 38.75, 38.75, 38.75, 36.25, 36.25, 36.25, 36.25, 36.25,
36.25, 36.25, 36.25, 36.25, 36.25, 36.25, 36.25, 36.25, 36.25,
36.25, 36.25, 36.25, 36.25, 36.25, 36.25, 36.25, 36.25, 36.25,
36.25, 36.25, 33.75, 33.75, 33.75, 33.75, 33.75, 33.75, 33.75,
33.75, 33.75, 33.75, 33.75, 33.75, 33.75, 33.75, 33.75, 33.75,
33.75, 33.75, 33.75, 33.75, 33.75, 33.75, 33.75, 33.75, 33.75,
31.25, 31.25, 31.25, 31.25, 31.25, 31.25, 31.25, 31.25, 31.25,
31.25, 31.25, 31.25, 31.25, 31.25, 31.25, 31.25, 31.25, 31.25,
31.25, 31.25, 31.25, 31.25, 31.25, 31.25, 31.25), longitud = c(-126.25,
-103.75, -101.25, -98.75, -96.25, -93.75, -91.25, -88.75, -86.25,
-83.75, -81.25, -123.75, -78.75, -76.25, -73.75, -71.25, -68.75,
-66.25, -121.25, -118.75, -116.25, -113.75, -111.25, -108.75,
-106.25, -126.25, -103.75, -101.25, -98.75, -96.25, -93.75, -91.25,
-88.75, -86.25, -83.75, -81.25, -123.75, -78.75, -76.25, -73.75,
-71.25, -68.75, -66.25, -121.25, -118.75, -116.25, -113.75, -111.25,
-108.75, -106.25, -126.25, -103.75, -101.25, -98.75, -96.25,
-93.75, -91.25, -88.75, -86.25, -83.75, -81.25, -123.75, -78.75,
-76.25, -73.75, -71.25, -68.75, -66.25, -121.25, -118.75, -116.25,
-113.75, -111.25, -108.75, -106.25, -126.25, -103.75, -101.25,
-98.75, -96.25, -93.75, -91.25, -88.75, -86.25, -83.75, -81.25,
-123.75, -78.75, -76.25, -73.75, -71.25, -68.75, -66.25, -121.25,
-118.75, -116.25, -113.75, -111.25, -108.75, -106.25, -126.25,
-103.75, -101.25, -98.75, -96.25, -93.75, -91.25, -88.75, -86.25,
-83.75, -81.25, -123.75, -78.75, -76.25, -73.75, -71.25, -68.75,
-66.25, -121.25, -118.75, -116.25, -113.75, -111.25, -108.75,
-106.25, -126.25, -103.75, -101.25, -98.75, -96.25, -93.75, -91.25,
-88.75, -86.25, -83.75, -81.25, -123.75, -78.75, -76.25, -73.75,
-71.25, -68.75, -66.25, -121.25, -118.75, -116.25, -113.75, -111.25,
-108.75, -106.25, -126.25, -103.75, -101.25, -98.75, -96.25,
-93.75, -91.25, -88.75, -86.25, -83.75, -81.25, -123.75, -78.75,
-76.25, -73.75, -71.25, -68.75, -66.25, -121.25, -118.75, -116.25,
-113.75, -111.25, -108.75, -106.25, -126.25, -103.75, -101.25,
-98.75, -96.25, -93.75, -91.25, -88.75, -86.25, -83.75, -81.25,
-123.75, -78.75, -76.25, -73.75, -71.25, -68.75, -66.25, -121.25,
-118.75, -116.25, -113.75, -111.25, -108.75, -106.25, -126.25,
-103.75, -101.25, -98.75, -96.25, -93.75, -91.25, -88.75, -86.25,
-83.75, -81.25, -123.75, -78.75, -76.25, -73.75, -71.25, -68.75,
-66.25, -121.25, -118.75, -116.25, -113.75, -111.25, -108.75,
-106.25, -126.25, -103.75, -101.25, -98.75, -96.25, -93.75, -91.25,
-88.75, -86.25, -83.75, -81.25, -123.75, -78.75, -76.25, -73.75,
-71.25, -68.75, -66.25, -121.25, -118.75, -116.25, -113.75, -111.25,
-108.75, -106.25, -126.25, -103.75, -101.25, -98.75, -96.25,
-93.75, -91.25, -88.75, -86.25, -83.75, -81.25, -123.75, -78.75,
-76.25, -73.75, -71.25, -68.75, -66.25, -121.25, -118.75, -116.25,
-113.75, -111.25, -108.75, -106.25, -126.25, -103.75, -101.25,
-98.75, -96.25, -93.75, -91.25, -88.75, -86.25, -83.75, -81.25,
-123.75, -78.75, -76.25, -73.75, -71.25, -68.75, -66.25, -121.25,
-118.75, -116.25, -113.75, -111.25, -108.75, -106.25), alpha = c(7.60309222533426,
6.88469180677483, 6.45664379029578, 5.13839948562175, 4.25955173699646,
6.88737807596091, 9.33014763427653, 9.37078918811668, 10.8254395655956,
10.7217702486856, 8.25299099074721, 6.15268326979142, 9.4261159518436,
10.7248520062669, 12.8300618223813, 7.9265524964983, 7.94295666154636,
7.46625786555931, 7.56556865230168, 7.62786077004313, 5.74129980047977,
3.60345752216216, 2.98378133573376, 4.06246062593975, 6.09423805608539,
1.90714662608465, 1.32852243192603, 1.14842741585065, 1.54455493550053,
2.9152792973547, 3.67507460999973, 2.92510129986622, 2.34474660498852,
3.11634334074451, 3.98002221771088, 3.02240869243639, 1.8995531476821,
3.62726928025656, 4.16443100700448, 3.70487893567663, 5.04897810729231,
6.07529625033252, 5.51442260743417, 1.52550408841981, 1.39664147581775,
0.93370996523883, 0.993750171191685, 0.730281791311035, 1.58125599500704,
1.3087475123286, 1.30952715348641, 0.788946600975913, 0.893757337284135,
1.51953002030833, 2.52690173646684, 2.99714415098982, 2.76766401446812,
3.5996722945412, 2.94792040169986, 3.1646049664401, 1.98218533914301,
1.14549003497193, 1.85177581184193, 2.99624801935386, 4.10204300531073,
4.57978075589719, 4.36911341536489, 3.95549721499504, 1.05029001794944,
1.09967867085832, 0.907337301224834, 0.74793334485007, 0.643458335927013,
0.881695809668616, 1.35139805159708, 1.02337675428854, 0.589481802911291,
0.782701696660816, 1.14357240216679, 2.4217145770105, 3.78907597466113,
2.80165966848667, 2.57055186392962, 2.99371461133379, 2.12237487172916,
1.37577218215501, 1.34174952550437, 3.07227683756664, 2.94848459851143,
3.0405951068517, 3.69959229276298, 3.80568586485391, 4.56246886270398,
0.952283765826263, 0.873394032304038, 0.893264322658818, 0.921772504147367,
0.517448808895897, 0.531008770655483, 0.982187809897314, 8.51041654178847,
3.59970105788619, 3.52147638507538, 4.28828666339891, 4.50980753329644,
5.33662106235463, 7.94632415111403, 5.99394336455509, 13.0157124981049,
12.2532204218057, 4.41299762761285, 7.17437154746178, 8.93394336880359,
10.9822254022821, 8.25946293412282, 8.0784872395404, 5.87963096146566,
10.5304989760356, 6.5265728685238, 7.25864073856438, 5.69307432139742,
7.85512705530055, 4.8457593175321, 3.75781927062404, 3.57161208333275,
9.22567091996363, 3.05261381191976, 3.35191688780187, 2.55402488578562,
2.22098528289277, 2.96476634780029, 4.33492777725925, 6.80585097894916,
10.0469893613946, 11.2359910066214, 11.3632449446646, 5.47652057362349,
12.1624004362306, 10.906817159447, 8.07627339240105, 7.51330523102997,
5.16215265151748, 8.55032418997155, 4.32936420681027, 7.70907588066477,
8.42854189722774, 7.1928228994093, 6.45175169812366, 3.78985482198053,
3.54947306301432, 7.16881679031781, 3.07443845739828, 2.76842384012895,
2.78211491127966, 2.63035826591286, 3.4029716238904, 3.79297046444767,
3.53880798407592, 5.43870453261712, 5.07920649228422, 12.9546584619937,
4.02328957639244, 10.3525744201763, 9.64925351685097, 5.46595977775097,
4.05307955253949, 4.07707662227455, 10.6238044923982, 4.28532904283762,
4.33691865638529, 4.43046602675603, 1.84292837586937, 4.49308486235944,
4.5312491956388, 4.79593991740801, 4.67537444232058, 2.41379396626427,
1.6699839123448, 1.89572963263843, 2.22674742100158, 3.48564721285749,
3.8009427060116, 3.43286888385444, 3.90053673711118, 4.29788725585451,
6.16514503593655, 3.11350018022043, 6.52731326633149, 4.3116517707907,
4.11635931501665, 4.11499820440921, 16.7599209530675, 14.6265070254832,
1.49314782562134, 1.98994667463885, 2.92130264154463, 2.70838250336083,
3.34117328175, 3.91770992600132, 2.80208780496034, 2.00191633504495,
4.12918103670829, 1.28656939963522, 1.38863966287248, 1.78543227774678,
2.3555491091684, 2.44967910877932, 3.06488070551261, 4.37519081404913,
5.71719662541664, 6.75682459734961, 1.82957832972716, 4.76407261260154,
5.79230215496683, 6.08921418184509, 16.635224158981, 16.3724225330387,
12.773133419787, 1.87266595478174, 2.07424096118467, 2.96355741615362,
2.68792506933465, 2.23337088010038, 3.34812977863271, 4.07483120227904,
1.71875921804878, 1.71002003692606, 0.858766984261838, 1.38836165005552,
1.8415780261283, 2.79509249040873, 3.89521695832594, 6.12662970318769,
7.14522432244917, 7.32755528428401, 5.41117560909515, 1.50827431411436,
4.77597939698993, 6.13393213534125, 11.7013078259801, 15.1212970305127,
15.8674028990548, 13.9693348877488, 1.52007871257504, 1.84876171232931,
1.30120540757862, 1.12892646601196, 1.07047177886132, 1.32716436312834,
3.10876495992507, 1.75807766831746, 0.914497649253801, 1.12047329941134,
1.43622641814638, 2.12006520012993, 2.88988393073478, 3.51764448501451,
5.13344985378897, 7.05701577117932, 7.18415445216388, 4.5821021978293,
1.66349639592564, 4.47536325758739, 7.05855758484088, 9.97213756310525,
13.1549213491357, 12.537054084307, 12.2475850305256, 1.26961607952348,
0.964343386261585, 0.747461361797493, 0.702539557294478, 0.99492613835112,
1.84288858917705, 1.34486121041946, 2.19465733527654, 1.14554324029827,
1.29950059741933, 1.84835524499147, 2.90217058598644, 3.40877391353338,
4.05446746291369, 4.54573766784205, 5.2530824394743, 3.88147601459954,
3.23835887254304, 2.27552016157486, 3.82304504413186, 6.03003614245222,
6.2407200878979, 6.97460543977307, 8.72201215747591, 9.43442067857835,
2.42403203554782, 1.57288193401563, 1.00546480164572, 0.785258620844128,
0.659835868225952, 1.18874246318751, 0.951280184150778)), class = "data.frame", row.names = c(NA,
-300L))
我想使用经度和纬度来设置位置,但是创建一个带有 alpha 值的纹理贴图,知道吗? (类似于matlab的geoshow函数)
期望的输出是这样的:
我认为以下解决方案可能有效。首先我加载一些 R 包:
library(rnaturalearth)
library(stars)
library(tmap)
然后我需要美国各州的多边形数据
us_states <- ne_states(country = "United States of America", returnclass = "sf")
# exclude hawaii and alaska
us_states <- us_states[!us_states$name %in% c("Hawaii", "Alaska"), ]
然后我加载你的输入数据
input_coords <- structure(list(latitud = c(
51.25, 51.25, 51.25, 51.25, 51.25,
51.25, 51.25, 51.25, 51.25, 51.25, 51.25, 51.25, 51.25, 51.25,
51.25, 51.25, 51.25, 51.25, 51.25, 51.25, 51.25, 51.25, 51.25,
51.25, 51.25, 28.75, 28.75, 28.75, 28.75, 28.75, 28.75, 28.75,
28.75, 28.75, 28.75, 28.75, 28.75, 28.75, 28.75, 28.75, 28.75,
28.75, 28.75, 28.75, 28.75, 28.75, 28.75, 28.75, 28.75, 28.75,
26.25, 26.25, 26.25, 26.25, 26.25, 26.25, 26.25, 26.25, 26.25,
26.25, 26.25, 26.25, 26.25, 26.25, 26.25, 26.25, 26.25, 26.25,
26.25, 26.25, 26.25, 26.25, 26.25, 26.25, 26.25, 23.75, 23.75,
23.75, 23.75, 23.75, 23.75, 23.75, 23.75, 23.75, 23.75, 23.75,
23.75, 23.75, 23.75, 23.75, 23.75, 23.75, 23.75, 23.75, 23.75,
23.75, 23.75, 23.75, 23.75, 23.75, 48.75, 48.75, 48.75, 48.75,
48.75, 48.75, 48.75, 48.75, 48.75, 48.75, 48.75, 48.75, 48.75,
48.75, 48.75, 48.75, 48.75, 48.75, 48.75, 48.75, 48.75, 48.75,
48.75, 48.75, 48.75, 46.25, 46.25, 46.25, 46.25, 46.25, 46.25,
46.25, 46.25, 46.25, 46.25, 46.25, 46.25, 46.25, 46.25, 46.25,
46.25, 46.25, 46.25, 46.25, 46.25, 46.25, 46.25, 46.25, 46.25,
46.25, 43.75, 43.75, 43.75, 43.75, 43.75, 43.75, 43.75, 43.75,
43.75, 43.75, 43.75, 43.75, 43.75, 43.75, 43.75, 43.75, 43.75,
43.75, 43.75, 43.75, 43.75, 43.75, 43.75, 43.75, 43.75, 41.25,
41.25, 41.25, 41.25, 41.25, 41.25, 41.25, 41.25, 41.25, 41.25,
41.25, 41.25, 41.25, 41.25, 41.25, 41.25, 41.25, 41.25, 41.25,
41.25, 41.25, 41.25, 41.25, 41.25, 41.25, 38.75, 38.75, 38.75,
38.75, 38.75, 38.75, 38.75, 38.75, 38.75, 38.75, 38.75, 38.75,
38.75, 38.75, 38.75, 38.75, 38.75, 38.75, 38.75, 38.75, 38.75,
38.75, 38.75, 38.75, 38.75, 36.25, 36.25, 36.25, 36.25, 36.25,
36.25, 36.25, 36.25, 36.25, 36.25, 36.25, 36.25, 36.25, 36.25,
36.25, 36.25, 36.25, 36.25, 36.25, 36.25, 36.25, 36.25, 36.25,
36.25, 36.25, 33.75, 33.75, 33.75, 33.75, 33.75, 33.75, 33.75,
33.75, 33.75, 33.75, 33.75, 33.75, 33.75, 33.75, 33.75, 33.75,
33.75, 33.75, 33.75, 33.75, 33.75, 33.75, 33.75, 33.75, 33.75,
31.25, 31.25, 31.25, 31.25, 31.25, 31.25, 31.25, 31.25, 31.25,
31.25, 31.25, 31.25, 31.25, 31.25, 31.25, 31.25, 31.25, 31.25,
31.25, 31.25, 31.25, 31.25, 31.25, 31.25, 31.25
), longitud = c(
-126.25,
-103.75, -101.25, -98.75, -96.25, -93.75, -91.25, -88.75, -86.25,
-83.75, -81.25, -123.75, -78.75, -76.25, -73.75, -71.25, -68.75,
-66.25, -121.25, -118.75, -116.25, -113.75, -111.25, -108.75,
-106.25, -126.25, -103.75, -101.25, -98.75, -96.25, -93.75, -91.25,
-88.75, -86.25, -83.75, -81.25, -123.75, -78.75, -76.25, -73.75,
-71.25, -68.75, -66.25, -121.25, -118.75, -116.25, -113.75, -111.25,
-108.75, -106.25, -126.25, -103.75, -101.25, -98.75, -96.25,
-93.75, -91.25, -88.75, -86.25, -83.75, -81.25, -123.75, -78.75,
-76.25, -73.75, -71.25, -68.75, -66.25, -121.25, -118.75, -116.25,
-113.75, -111.25, -108.75, -106.25, -126.25, -103.75, -101.25,
-98.75, -96.25, -93.75, -91.25, -88.75, -86.25, -83.75, -81.25,
-123.75, -78.75, -76.25, -73.75, -71.25, -68.75, -66.25, -121.25,
-118.75, -116.25, -113.75, -111.25, -108.75, -106.25, -126.25,
-103.75, -101.25, -98.75, -96.25, -93.75, -91.25, -88.75, -86.25,
-83.75, -81.25, -123.75, -78.75, -76.25, -73.75, -71.25, -68.75,
-66.25, -121.25, -118.75, -116.25, -113.75, -111.25, -108.75,
-106.25, -126.25, -103.75, -101.25, -98.75, -96.25, -93.75, -91.25,
-88.75, -86.25, -83.75, -81.25, -123.75, -78.75, -76.25, -73.75,
-71.25, -68.75, -66.25, -121.25, -118.75, -116.25, -113.75, -111.25,
-108.75, -106.25, -126.25, -103.75, -101.25, -98.75, -96.25,
-93.75, -91.25, -88.75, -86.25, -83.75, -81.25, -123.75, -78.75,
-76.25, -73.75, -71.25, -68.75, -66.25, -121.25, -118.75, -116.25,
-113.75, -111.25, -108.75, -106.25, -126.25, -103.75, -101.25,
-98.75, -96.25, -93.75, -91.25, -88.75, -86.25, -83.75, -81.25,
-123.75, -78.75, -76.25, -73.75, -71.25, -68.75, -66.25, -121.25,
-118.75, -116.25, -113.75, -111.25, -108.75, -106.25, -126.25,
-103.75, -101.25, -98.75, -96.25, -93.75, -91.25, -88.75, -86.25,
-83.75, -81.25, -123.75, -78.75, -76.25, -73.75, -71.25, -68.75,
-66.25, -121.25, -118.75, -116.25, -113.75, -111.25, -108.75,
-106.25, -126.25, -103.75, -101.25, -98.75, -96.25, -93.75, -91.25,
-88.75, -86.25, -83.75, -81.25, -123.75, -78.75, -76.25, -73.75,
-71.25, -68.75, -66.25, -121.25, -118.75, -116.25, -113.75, -111.25,
-108.75, -106.25, -126.25, -103.75, -101.25, -98.75, -96.25,
-93.75, -91.25, -88.75, -86.25, -83.75, -81.25, -123.75, -78.75,
-76.25, -73.75, -71.25, -68.75, -66.25, -121.25, -118.75, -116.25,
-113.75, -111.25, -108.75, -106.25, -126.25, -103.75, -101.25,
-98.75, -96.25, -93.75, -91.25, -88.75, -86.25, -83.75, -81.25,
-123.75, -78.75, -76.25, -73.75, -71.25, -68.75, -66.25, -121.25,
-118.75, -116.25, -113.75, -111.25, -108.75, -106.25
), alpha = c(
7.60309222533426,
6.88469180677483, 6.45664379029578, 5.13839948562175, 4.25955173699646,
6.88737807596091, 9.33014763427653, 9.37078918811668, 10.8254395655956,
10.7217702486856, 8.25299099074721, 6.15268326979142, 9.4261159518436,
10.7248520062669, 12.8300618223813, 7.9265524964983, 7.94295666154636,
7.46625786555931, 7.56556865230168, 7.62786077004313, 5.74129980047977,
3.60345752216216, 2.98378133573376, 4.06246062593975, 6.09423805608539,
1.90714662608465, 1.32852243192603, 1.14842741585065, 1.54455493550053,
2.9152792973547, 3.67507460999973, 2.92510129986622, 2.34474660498852,
3.11634334074451, 3.98002221771088, 3.02240869243639, 1.8995531476821,
3.62726928025656, 4.16443100700448, 3.70487893567663, 5.04897810729231,
6.07529625033252, 5.51442260743417, 1.52550408841981, 1.39664147581775,
0.93370996523883, 0.993750171191685, 0.730281791311035, 1.58125599500704,
1.3087475123286, 1.30952715348641, 0.788946600975913, 0.893757337284135,
1.51953002030833, 2.52690173646684, 2.99714415098982, 2.76766401446812,
3.5996722945412, 2.94792040169986, 3.1646049664401, 1.98218533914301,
1.14549003497193, 1.85177581184193, 2.99624801935386, 4.10204300531073,
4.57978075589719, 4.36911341536489, 3.95549721499504, 1.05029001794944,
1.09967867085832, 0.907337301224834, 0.74793334485007, 0.643458335927013,
0.881695809668616, 1.35139805159708, 1.02337675428854, 0.589481802911291,
0.782701696660816, 1.14357240216679, 2.4217145770105, 3.78907597466113,
2.80165966848667, 2.57055186392962, 2.99371461133379, 2.12237487172916,
1.37577218215501, 1.34174952550437, 3.07227683756664, 2.94848459851143,
3.0405951068517, 3.69959229276298, 3.80568586485391, 4.56246886270398,
0.952283765826263, 0.873394032304038, 0.893264322658818, 0.921772504147367,
0.517448808895897, 0.531008770655483, 0.982187809897314, 8.51041654178847,
3.59970105788619, 3.52147638507538, 4.28828666339891, 4.50980753329644,
5.33662106235463, 7.94632415111403, 5.99394336455509, 13.0157124981049,
12.2532204218057, 4.41299762761285, 7.17437154746178, 8.93394336880359,
10.9822254022821, 8.25946293412282, 8.0784872395404, 5.87963096146566,
10.5304989760356, 6.5265728685238, 7.25864073856438, 5.69307432139742,
7.85512705530055, 4.8457593175321, 3.75781927062404, 3.57161208333275,
9.22567091996363, 3.05261381191976, 3.35191688780187, 2.55402488578562,
2.22098528289277, 2.96476634780029, 4.33492777725925, 6.80585097894916,
10.0469893613946, 11.2359910066214, 11.3632449446646, 5.47652057362349,
12.1624004362306, 10.906817159447, 8.07627339240105, 7.51330523102997,
5.16215265151748, 8.55032418997155, 4.32936420681027, 7.70907588066477,
8.42854189722774, 7.1928228994093, 6.45175169812366, 3.78985482198053,
3.54947306301432, 7.16881679031781, 3.07443845739828, 2.76842384012895,
2.78211491127966, 2.63035826591286, 3.4029716238904, 3.79297046444767,
3.53880798407592, 5.43870453261712, 5.07920649228422, 12.9546584619937,
4.02328957639244, 10.3525744201763, 9.64925351685097, 5.46595977775097,
4.05307955253949, 4.07707662227455, 10.6238044923982, 4.28532904283762,
4.33691865638529, 4.43046602675603, 1.84292837586937, 4.49308486235944,
4.5312491956388, 4.79593991740801, 4.67537444232058, 2.41379396626427,
1.6699839123448, 1.89572963263843, 2.22674742100158, 3.48564721285749,
3.8009427060116, 3.43286888385444, 3.90053673711118, 4.29788725585451,
6.16514503593655, 3.11350018022043, 6.52731326633149, 4.3116517707907,
4.11635931501665, 4.11499820440921, 16.7599209530675, 14.6265070254832,
1.49314782562134, 1.98994667463885, 2.92130264154463, 2.70838250336083,
3.34117328175, 3.91770992600132, 2.80208780496034, 2.00191633504495,
4.12918103670829, 1.28656939963522, 1.38863966287248, 1.78543227774678,
2.3555491091684, 2.44967910877932, 3.06488070551261, 4.37519081404913,
5.71719662541664, 6.75682459734961, 1.82957832972716, 4.76407261260154,
5.79230215496683, 6.08921418184509, 16.635224158981, 16.3724225330387,
12.773133419787, 1.87266595478174, 2.07424096118467, 2.96355741615362,
2.68792506933465, 2.23337088010038, 3.34812977863271, 4.07483120227904,
1.71875921804878, 1.71002003692606, 0.858766984261838, 1.38836165005552,
1.8415780261283, 2.79509249040873, 3.89521695832594, 6.12662970318769,
7.14522432244917, 7.32755528428401, 5.41117560909515, 1.50827431411436,
4.77597939698993, 6.13393213534125, 11.7013078259801, 15.1212970305127,
15.8674028990548, 13.9693348877488, 1.52007871257504, 1.84876171232931,
1.30120540757862, 1.12892646601196, 1.07047177886132, 1.32716436312834,
3.10876495992507, 1.75807766831746, 0.914497649253801, 1.12047329941134,
1.43622641814638, 2.12006520012993, 2.88988393073478, 3.51764448501451,
5.13344985378897, 7.05701577117932, 7.18415445216388, 4.5821021978293,
1.66349639592564, 4.47536325758739, 7.05855758484088, 9.97213756310525,
13.1549213491357, 12.537054084307, 12.2475850305256, 1.26961607952348,
0.964343386261585, 0.747461361797493, 0.702539557294478, 0.99492613835112,
1.84288858917705, 1.34486121041946, 2.19465733527654, 1.14554324029827,
1.29950059741933, 1.84835524499147, 2.90217058598644, 3.40877391353338,
4.05446746291369, 4.54573766784205, 5.2530824394743, 3.88147601459954,
3.23835887254304, 2.27552016157486, 3.82304504413186, 6.03003614245222,
6.2407200878979, 6.97460543977307, 8.72201215747591, 9.43442067857835,
2.42403203554782, 1.57288193401563, 1.00546480164572, 0.785258620844128,
0.659835868225952, 1.18874246318751, 0.951280184150778
)), class = "data.frame", row.names = c(
NA,
-300L
))
转化为sf
input_sf <- st_as_sf(input_coords, coords = c("longitud", "latitud"), crs = 4326)
为 st_rasterize
创建 stars
对象
input_template <- st_as_stars(st_bbox(input_sf), dx = 2.5, dy = 2.5)
input_stars <- st_rasterize(input_sf, input_template)
最后,用tmap绘图
tm_shape(input_stars) +
tm_raster(n = 10, legend.show = FALSE, palette = "viridis", contrast = c(0.1, 0.9)) +
tm_shape(us_states) +
tm_borders(lwd = 2, col = "darkgrey")
由 reprex package (v0.3.0)
于 2020-10-13 创建
编辑
您需要为网格添加以下代码:
tm_shape(input_stars) +
tm_raster(n = 10, legend.show = FALSE, palette = "viridis", contrast = c(0.1, 0.9)) +
tm_shape(us_states) +
tm_borders(lwd = 2, col = "darkgrey") +
tm_grid()
由 reprex package (v0.3.0)
于 2020-10-14 创建
我想为美国经纬度不同的点创建alpha值的纹理贴图。
目前,我最多只能使用此代码生成以下图像:
map('state', plot = TRUE, fill = FALSE, col = palette())
points(Fit_Gamma_January$longitud,Fit_Gamma_January$latitud, col="red", cex=1.5)
我的数据是:
dput(Fit_Gamma_January)
structure(list(latitud = c(51.25, 51.25, 51.25, 51.25, 51.25,
51.25, 51.25, 51.25, 51.25, 51.25, 51.25, 51.25, 51.25, 51.25,
51.25, 51.25, 51.25, 51.25, 51.25, 51.25, 51.25, 51.25, 51.25,
51.25, 51.25, 28.75, 28.75, 28.75, 28.75, 28.75, 28.75, 28.75,
28.75, 28.75, 28.75, 28.75, 28.75, 28.75, 28.75, 28.75, 28.75,
28.75, 28.75, 28.75, 28.75, 28.75, 28.75, 28.75, 28.75, 28.75,
26.25, 26.25, 26.25, 26.25, 26.25, 26.25, 26.25, 26.25, 26.25,
26.25, 26.25, 26.25, 26.25, 26.25, 26.25, 26.25, 26.25, 26.25,
26.25, 26.25, 26.25, 26.25, 26.25, 26.25, 26.25, 23.75, 23.75,
23.75, 23.75, 23.75, 23.75, 23.75, 23.75, 23.75, 23.75, 23.75,
23.75, 23.75, 23.75, 23.75, 23.75, 23.75, 23.75, 23.75, 23.75,
23.75, 23.75, 23.75, 23.75, 23.75, 48.75, 48.75, 48.75, 48.75,
48.75, 48.75, 48.75, 48.75, 48.75, 48.75, 48.75, 48.75, 48.75,
48.75, 48.75, 48.75, 48.75, 48.75, 48.75, 48.75, 48.75, 48.75,
48.75, 48.75, 48.75, 46.25, 46.25, 46.25, 46.25, 46.25, 46.25,
46.25, 46.25, 46.25, 46.25, 46.25, 46.25, 46.25, 46.25, 46.25,
46.25, 46.25, 46.25, 46.25, 46.25, 46.25, 46.25, 46.25, 46.25,
46.25, 43.75, 43.75, 43.75, 43.75, 43.75, 43.75, 43.75, 43.75,
43.75, 43.75, 43.75, 43.75, 43.75, 43.75, 43.75, 43.75, 43.75,
43.75, 43.75, 43.75, 43.75, 43.75, 43.75, 43.75, 43.75, 41.25,
41.25, 41.25, 41.25, 41.25, 41.25, 41.25, 41.25, 41.25, 41.25,
41.25, 41.25, 41.25, 41.25, 41.25, 41.25, 41.25, 41.25, 41.25,
41.25, 41.25, 41.25, 41.25, 41.25, 41.25, 38.75, 38.75, 38.75,
38.75, 38.75, 38.75, 38.75, 38.75, 38.75, 38.75, 38.75, 38.75,
38.75, 38.75, 38.75, 38.75, 38.75, 38.75, 38.75, 38.75, 38.75,
38.75, 38.75, 38.75, 38.75, 36.25, 36.25, 36.25, 36.25, 36.25,
36.25, 36.25, 36.25, 36.25, 36.25, 36.25, 36.25, 36.25, 36.25,
36.25, 36.25, 36.25, 36.25, 36.25, 36.25, 36.25, 36.25, 36.25,
36.25, 36.25, 33.75, 33.75, 33.75, 33.75, 33.75, 33.75, 33.75,
33.75, 33.75, 33.75, 33.75, 33.75, 33.75, 33.75, 33.75, 33.75,
33.75, 33.75, 33.75, 33.75, 33.75, 33.75, 33.75, 33.75, 33.75,
31.25, 31.25, 31.25, 31.25, 31.25, 31.25, 31.25, 31.25, 31.25,
31.25, 31.25, 31.25, 31.25, 31.25, 31.25, 31.25, 31.25, 31.25,
31.25, 31.25, 31.25, 31.25, 31.25, 31.25, 31.25), longitud = c(-126.25,
-103.75, -101.25, -98.75, -96.25, -93.75, -91.25, -88.75, -86.25,
-83.75, -81.25, -123.75, -78.75, -76.25, -73.75, -71.25, -68.75,
-66.25, -121.25, -118.75, -116.25, -113.75, -111.25, -108.75,
-106.25, -126.25, -103.75, -101.25, -98.75, -96.25, -93.75, -91.25,
-88.75, -86.25, -83.75, -81.25, -123.75, -78.75, -76.25, -73.75,
-71.25, -68.75, -66.25, -121.25, -118.75, -116.25, -113.75, -111.25,
-108.75, -106.25, -126.25, -103.75, -101.25, -98.75, -96.25,
-93.75, -91.25, -88.75, -86.25, -83.75, -81.25, -123.75, -78.75,
-76.25, -73.75, -71.25, -68.75, -66.25, -121.25, -118.75, -116.25,
-113.75, -111.25, -108.75, -106.25, -126.25, -103.75, -101.25,
-98.75, -96.25, -93.75, -91.25, -88.75, -86.25, -83.75, -81.25,
-123.75, -78.75, -76.25, -73.75, -71.25, -68.75, -66.25, -121.25,
-118.75, -116.25, -113.75, -111.25, -108.75, -106.25, -126.25,
-103.75, -101.25, -98.75, -96.25, -93.75, -91.25, -88.75, -86.25,
-83.75, -81.25, -123.75, -78.75, -76.25, -73.75, -71.25, -68.75,
-66.25, -121.25, -118.75, -116.25, -113.75, -111.25, -108.75,
-106.25, -126.25, -103.75, -101.25, -98.75, -96.25, -93.75, -91.25,
-88.75, -86.25, -83.75, -81.25, -123.75, -78.75, -76.25, -73.75,
-71.25, -68.75, -66.25, -121.25, -118.75, -116.25, -113.75, -111.25,
-108.75, -106.25, -126.25, -103.75, -101.25, -98.75, -96.25,
-93.75, -91.25, -88.75, -86.25, -83.75, -81.25, -123.75, -78.75,
-76.25, -73.75, -71.25, -68.75, -66.25, -121.25, -118.75, -116.25,
-113.75, -111.25, -108.75, -106.25, -126.25, -103.75, -101.25,
-98.75, -96.25, -93.75, -91.25, -88.75, -86.25, -83.75, -81.25,
-123.75, -78.75, -76.25, -73.75, -71.25, -68.75, -66.25, -121.25,
-118.75, -116.25, -113.75, -111.25, -108.75, -106.25, -126.25,
-103.75, -101.25, -98.75, -96.25, -93.75, -91.25, -88.75, -86.25,
-83.75, -81.25, -123.75, -78.75, -76.25, -73.75, -71.25, -68.75,
-66.25, -121.25, -118.75, -116.25, -113.75, -111.25, -108.75,
-106.25, -126.25, -103.75, -101.25, -98.75, -96.25, -93.75, -91.25,
-88.75, -86.25, -83.75, -81.25, -123.75, -78.75, -76.25, -73.75,
-71.25, -68.75, -66.25, -121.25, -118.75, -116.25, -113.75, -111.25,
-108.75, -106.25, -126.25, -103.75, -101.25, -98.75, -96.25,
-93.75, -91.25, -88.75, -86.25, -83.75, -81.25, -123.75, -78.75,
-76.25, -73.75, -71.25, -68.75, -66.25, -121.25, -118.75, -116.25,
-113.75, -111.25, -108.75, -106.25, -126.25, -103.75, -101.25,
-98.75, -96.25, -93.75, -91.25, -88.75, -86.25, -83.75, -81.25,
-123.75, -78.75, -76.25, -73.75, -71.25, -68.75, -66.25, -121.25,
-118.75, -116.25, -113.75, -111.25, -108.75, -106.25), alpha = c(7.60309222533426,
6.88469180677483, 6.45664379029578, 5.13839948562175, 4.25955173699646,
6.88737807596091, 9.33014763427653, 9.37078918811668, 10.8254395655956,
10.7217702486856, 8.25299099074721, 6.15268326979142, 9.4261159518436,
10.7248520062669, 12.8300618223813, 7.9265524964983, 7.94295666154636,
7.46625786555931, 7.56556865230168, 7.62786077004313, 5.74129980047977,
3.60345752216216, 2.98378133573376, 4.06246062593975, 6.09423805608539,
1.90714662608465, 1.32852243192603, 1.14842741585065, 1.54455493550053,
2.9152792973547, 3.67507460999973, 2.92510129986622, 2.34474660498852,
3.11634334074451, 3.98002221771088, 3.02240869243639, 1.8995531476821,
3.62726928025656, 4.16443100700448, 3.70487893567663, 5.04897810729231,
6.07529625033252, 5.51442260743417, 1.52550408841981, 1.39664147581775,
0.93370996523883, 0.993750171191685, 0.730281791311035, 1.58125599500704,
1.3087475123286, 1.30952715348641, 0.788946600975913, 0.893757337284135,
1.51953002030833, 2.52690173646684, 2.99714415098982, 2.76766401446812,
3.5996722945412, 2.94792040169986, 3.1646049664401, 1.98218533914301,
1.14549003497193, 1.85177581184193, 2.99624801935386, 4.10204300531073,
4.57978075589719, 4.36911341536489, 3.95549721499504, 1.05029001794944,
1.09967867085832, 0.907337301224834, 0.74793334485007, 0.643458335927013,
0.881695809668616, 1.35139805159708, 1.02337675428854, 0.589481802911291,
0.782701696660816, 1.14357240216679, 2.4217145770105, 3.78907597466113,
2.80165966848667, 2.57055186392962, 2.99371461133379, 2.12237487172916,
1.37577218215501, 1.34174952550437, 3.07227683756664, 2.94848459851143,
3.0405951068517, 3.69959229276298, 3.80568586485391, 4.56246886270398,
0.952283765826263, 0.873394032304038, 0.893264322658818, 0.921772504147367,
0.517448808895897, 0.531008770655483, 0.982187809897314, 8.51041654178847,
3.59970105788619, 3.52147638507538, 4.28828666339891, 4.50980753329644,
5.33662106235463, 7.94632415111403, 5.99394336455509, 13.0157124981049,
12.2532204218057, 4.41299762761285, 7.17437154746178, 8.93394336880359,
10.9822254022821, 8.25946293412282, 8.0784872395404, 5.87963096146566,
10.5304989760356, 6.5265728685238, 7.25864073856438, 5.69307432139742,
7.85512705530055, 4.8457593175321, 3.75781927062404, 3.57161208333275,
9.22567091996363, 3.05261381191976, 3.35191688780187, 2.55402488578562,
2.22098528289277, 2.96476634780029, 4.33492777725925, 6.80585097894916,
10.0469893613946, 11.2359910066214, 11.3632449446646, 5.47652057362349,
12.1624004362306, 10.906817159447, 8.07627339240105, 7.51330523102997,
5.16215265151748, 8.55032418997155, 4.32936420681027, 7.70907588066477,
8.42854189722774, 7.1928228994093, 6.45175169812366, 3.78985482198053,
3.54947306301432, 7.16881679031781, 3.07443845739828, 2.76842384012895,
2.78211491127966, 2.63035826591286, 3.4029716238904, 3.79297046444767,
3.53880798407592, 5.43870453261712, 5.07920649228422, 12.9546584619937,
4.02328957639244, 10.3525744201763, 9.64925351685097, 5.46595977775097,
4.05307955253949, 4.07707662227455, 10.6238044923982, 4.28532904283762,
4.33691865638529, 4.43046602675603, 1.84292837586937, 4.49308486235944,
4.5312491956388, 4.79593991740801, 4.67537444232058, 2.41379396626427,
1.6699839123448, 1.89572963263843, 2.22674742100158, 3.48564721285749,
3.8009427060116, 3.43286888385444, 3.90053673711118, 4.29788725585451,
6.16514503593655, 3.11350018022043, 6.52731326633149, 4.3116517707907,
4.11635931501665, 4.11499820440921, 16.7599209530675, 14.6265070254832,
1.49314782562134, 1.98994667463885, 2.92130264154463, 2.70838250336083,
3.34117328175, 3.91770992600132, 2.80208780496034, 2.00191633504495,
4.12918103670829, 1.28656939963522, 1.38863966287248, 1.78543227774678,
2.3555491091684, 2.44967910877932, 3.06488070551261, 4.37519081404913,
5.71719662541664, 6.75682459734961, 1.82957832972716, 4.76407261260154,
5.79230215496683, 6.08921418184509, 16.635224158981, 16.3724225330387,
12.773133419787, 1.87266595478174, 2.07424096118467, 2.96355741615362,
2.68792506933465, 2.23337088010038, 3.34812977863271, 4.07483120227904,
1.71875921804878, 1.71002003692606, 0.858766984261838, 1.38836165005552,
1.8415780261283, 2.79509249040873, 3.89521695832594, 6.12662970318769,
7.14522432244917, 7.32755528428401, 5.41117560909515, 1.50827431411436,
4.77597939698993, 6.13393213534125, 11.7013078259801, 15.1212970305127,
15.8674028990548, 13.9693348877488, 1.52007871257504, 1.84876171232931,
1.30120540757862, 1.12892646601196, 1.07047177886132, 1.32716436312834,
3.10876495992507, 1.75807766831746, 0.914497649253801, 1.12047329941134,
1.43622641814638, 2.12006520012993, 2.88988393073478, 3.51764448501451,
5.13344985378897, 7.05701577117932, 7.18415445216388, 4.5821021978293,
1.66349639592564, 4.47536325758739, 7.05855758484088, 9.97213756310525,
13.1549213491357, 12.537054084307, 12.2475850305256, 1.26961607952348,
0.964343386261585, 0.747461361797493, 0.702539557294478, 0.99492613835112,
1.84288858917705, 1.34486121041946, 2.19465733527654, 1.14554324029827,
1.29950059741933, 1.84835524499147, 2.90217058598644, 3.40877391353338,
4.05446746291369, 4.54573766784205, 5.2530824394743, 3.88147601459954,
3.23835887254304, 2.27552016157486, 3.82304504413186, 6.03003614245222,
6.2407200878979, 6.97460543977307, 8.72201215747591, 9.43442067857835,
2.42403203554782, 1.57288193401563, 1.00546480164572, 0.785258620844128,
0.659835868225952, 1.18874246318751, 0.951280184150778)), class = "data.frame", row.names = c(NA,
-300L))
我想使用经度和纬度来设置位置,但是创建一个带有 alpha 值的纹理贴图,知道吗? (类似于matlab的geoshow函数)
期望的输出是这样的:
我认为以下解决方案可能有效。首先我加载一些 R 包:
library(rnaturalearth)
library(stars)
library(tmap)
然后我需要美国各州的多边形数据
us_states <- ne_states(country = "United States of America", returnclass = "sf")
# exclude hawaii and alaska
us_states <- us_states[!us_states$name %in% c("Hawaii", "Alaska"), ]
然后我加载你的输入数据
input_coords <- structure(list(latitud = c(
51.25, 51.25, 51.25, 51.25, 51.25,
51.25, 51.25, 51.25, 51.25, 51.25, 51.25, 51.25, 51.25, 51.25,
51.25, 51.25, 51.25, 51.25, 51.25, 51.25, 51.25, 51.25, 51.25,
51.25, 51.25, 28.75, 28.75, 28.75, 28.75, 28.75, 28.75, 28.75,
28.75, 28.75, 28.75, 28.75, 28.75, 28.75, 28.75, 28.75, 28.75,
28.75, 28.75, 28.75, 28.75, 28.75, 28.75, 28.75, 28.75, 28.75,
26.25, 26.25, 26.25, 26.25, 26.25, 26.25, 26.25, 26.25, 26.25,
26.25, 26.25, 26.25, 26.25, 26.25, 26.25, 26.25, 26.25, 26.25,
26.25, 26.25, 26.25, 26.25, 26.25, 26.25, 26.25, 23.75, 23.75,
23.75, 23.75, 23.75, 23.75, 23.75, 23.75, 23.75, 23.75, 23.75,
23.75, 23.75, 23.75, 23.75, 23.75, 23.75, 23.75, 23.75, 23.75,
23.75, 23.75, 23.75, 23.75, 23.75, 48.75, 48.75, 48.75, 48.75,
48.75, 48.75, 48.75, 48.75, 48.75, 48.75, 48.75, 48.75, 48.75,
48.75, 48.75, 48.75, 48.75, 48.75, 48.75, 48.75, 48.75, 48.75,
48.75, 48.75, 48.75, 46.25, 46.25, 46.25, 46.25, 46.25, 46.25,
46.25, 46.25, 46.25, 46.25, 46.25, 46.25, 46.25, 46.25, 46.25,
46.25, 46.25, 46.25, 46.25, 46.25, 46.25, 46.25, 46.25, 46.25,
46.25, 43.75, 43.75, 43.75, 43.75, 43.75, 43.75, 43.75, 43.75,
43.75, 43.75, 43.75, 43.75, 43.75, 43.75, 43.75, 43.75, 43.75,
43.75, 43.75, 43.75, 43.75, 43.75, 43.75, 43.75, 43.75, 41.25,
41.25, 41.25, 41.25, 41.25, 41.25, 41.25, 41.25, 41.25, 41.25,
41.25, 41.25, 41.25, 41.25, 41.25, 41.25, 41.25, 41.25, 41.25,
41.25, 41.25, 41.25, 41.25, 41.25, 41.25, 38.75, 38.75, 38.75,
38.75, 38.75, 38.75, 38.75, 38.75, 38.75, 38.75, 38.75, 38.75,
38.75, 38.75, 38.75, 38.75, 38.75, 38.75, 38.75, 38.75, 38.75,
38.75, 38.75, 38.75, 38.75, 36.25, 36.25, 36.25, 36.25, 36.25,
36.25, 36.25, 36.25, 36.25, 36.25, 36.25, 36.25, 36.25, 36.25,
36.25, 36.25, 36.25, 36.25, 36.25, 36.25, 36.25, 36.25, 36.25,
36.25, 36.25, 33.75, 33.75, 33.75, 33.75, 33.75, 33.75, 33.75,
33.75, 33.75, 33.75, 33.75, 33.75, 33.75, 33.75, 33.75, 33.75,
33.75, 33.75, 33.75, 33.75, 33.75, 33.75, 33.75, 33.75, 33.75,
31.25, 31.25, 31.25, 31.25, 31.25, 31.25, 31.25, 31.25, 31.25,
31.25, 31.25, 31.25, 31.25, 31.25, 31.25, 31.25, 31.25, 31.25,
31.25, 31.25, 31.25, 31.25, 31.25, 31.25, 31.25
), longitud = c(
-126.25,
-103.75, -101.25, -98.75, -96.25, -93.75, -91.25, -88.75, -86.25,
-83.75, -81.25, -123.75, -78.75, -76.25, -73.75, -71.25, -68.75,
-66.25, -121.25, -118.75, -116.25, -113.75, -111.25, -108.75,
-106.25, -126.25, -103.75, -101.25, -98.75, -96.25, -93.75, -91.25,
-88.75, -86.25, -83.75, -81.25, -123.75, -78.75, -76.25, -73.75,
-71.25, -68.75, -66.25, -121.25, -118.75, -116.25, -113.75, -111.25,
-108.75, -106.25, -126.25, -103.75, -101.25, -98.75, -96.25,
-93.75, -91.25, -88.75, -86.25, -83.75, -81.25, -123.75, -78.75,
-76.25, -73.75, -71.25, -68.75, -66.25, -121.25, -118.75, -116.25,
-113.75, -111.25, -108.75, -106.25, -126.25, -103.75, -101.25,
-98.75, -96.25, -93.75, -91.25, -88.75, -86.25, -83.75, -81.25,
-123.75, -78.75, -76.25, -73.75, -71.25, -68.75, -66.25, -121.25,
-118.75, -116.25, -113.75, -111.25, -108.75, -106.25, -126.25,
-103.75, -101.25, -98.75, -96.25, -93.75, -91.25, -88.75, -86.25,
-83.75, -81.25, -123.75, -78.75, -76.25, -73.75, -71.25, -68.75,
-66.25, -121.25, -118.75, -116.25, -113.75, -111.25, -108.75,
-106.25, -126.25, -103.75, -101.25, -98.75, -96.25, -93.75, -91.25,
-88.75, -86.25, -83.75, -81.25, -123.75, -78.75, -76.25, -73.75,
-71.25, -68.75, -66.25, -121.25, -118.75, -116.25, -113.75, -111.25,
-108.75, -106.25, -126.25, -103.75, -101.25, -98.75, -96.25,
-93.75, -91.25, -88.75, -86.25, -83.75, -81.25, -123.75, -78.75,
-76.25, -73.75, -71.25, -68.75, -66.25, -121.25, -118.75, -116.25,
-113.75, -111.25, -108.75, -106.25, -126.25, -103.75, -101.25,
-98.75, -96.25, -93.75, -91.25, -88.75, -86.25, -83.75, -81.25,
-123.75, -78.75, -76.25, -73.75, -71.25, -68.75, -66.25, -121.25,
-118.75, -116.25, -113.75, -111.25, -108.75, -106.25, -126.25,
-103.75, -101.25, -98.75, -96.25, -93.75, -91.25, -88.75, -86.25,
-83.75, -81.25, -123.75, -78.75, -76.25, -73.75, -71.25, -68.75,
-66.25, -121.25, -118.75, -116.25, -113.75, -111.25, -108.75,
-106.25, -126.25, -103.75, -101.25, -98.75, -96.25, -93.75, -91.25,
-88.75, -86.25, -83.75, -81.25, -123.75, -78.75, -76.25, -73.75,
-71.25, -68.75, -66.25, -121.25, -118.75, -116.25, -113.75, -111.25,
-108.75, -106.25, -126.25, -103.75, -101.25, -98.75, -96.25,
-93.75, -91.25, -88.75, -86.25, -83.75, -81.25, -123.75, -78.75,
-76.25, -73.75, -71.25, -68.75, -66.25, -121.25, -118.75, -116.25,
-113.75, -111.25, -108.75, -106.25, -126.25, -103.75, -101.25,
-98.75, -96.25, -93.75, -91.25, -88.75, -86.25, -83.75, -81.25,
-123.75, -78.75, -76.25, -73.75, -71.25, -68.75, -66.25, -121.25,
-118.75, -116.25, -113.75, -111.25, -108.75, -106.25
), alpha = c(
7.60309222533426,
6.88469180677483, 6.45664379029578, 5.13839948562175, 4.25955173699646,
6.88737807596091, 9.33014763427653, 9.37078918811668, 10.8254395655956,
10.7217702486856, 8.25299099074721, 6.15268326979142, 9.4261159518436,
10.7248520062669, 12.8300618223813, 7.9265524964983, 7.94295666154636,
7.46625786555931, 7.56556865230168, 7.62786077004313, 5.74129980047977,
3.60345752216216, 2.98378133573376, 4.06246062593975, 6.09423805608539,
1.90714662608465, 1.32852243192603, 1.14842741585065, 1.54455493550053,
2.9152792973547, 3.67507460999973, 2.92510129986622, 2.34474660498852,
3.11634334074451, 3.98002221771088, 3.02240869243639, 1.8995531476821,
3.62726928025656, 4.16443100700448, 3.70487893567663, 5.04897810729231,
6.07529625033252, 5.51442260743417, 1.52550408841981, 1.39664147581775,
0.93370996523883, 0.993750171191685, 0.730281791311035, 1.58125599500704,
1.3087475123286, 1.30952715348641, 0.788946600975913, 0.893757337284135,
1.51953002030833, 2.52690173646684, 2.99714415098982, 2.76766401446812,
3.5996722945412, 2.94792040169986, 3.1646049664401, 1.98218533914301,
1.14549003497193, 1.85177581184193, 2.99624801935386, 4.10204300531073,
4.57978075589719, 4.36911341536489, 3.95549721499504, 1.05029001794944,
1.09967867085832, 0.907337301224834, 0.74793334485007, 0.643458335927013,
0.881695809668616, 1.35139805159708, 1.02337675428854, 0.589481802911291,
0.782701696660816, 1.14357240216679, 2.4217145770105, 3.78907597466113,
2.80165966848667, 2.57055186392962, 2.99371461133379, 2.12237487172916,
1.37577218215501, 1.34174952550437, 3.07227683756664, 2.94848459851143,
3.0405951068517, 3.69959229276298, 3.80568586485391, 4.56246886270398,
0.952283765826263, 0.873394032304038, 0.893264322658818, 0.921772504147367,
0.517448808895897, 0.531008770655483, 0.982187809897314, 8.51041654178847,
3.59970105788619, 3.52147638507538, 4.28828666339891, 4.50980753329644,
5.33662106235463, 7.94632415111403, 5.99394336455509, 13.0157124981049,
12.2532204218057, 4.41299762761285, 7.17437154746178, 8.93394336880359,
10.9822254022821, 8.25946293412282, 8.0784872395404, 5.87963096146566,
10.5304989760356, 6.5265728685238, 7.25864073856438, 5.69307432139742,
7.85512705530055, 4.8457593175321, 3.75781927062404, 3.57161208333275,
9.22567091996363, 3.05261381191976, 3.35191688780187, 2.55402488578562,
2.22098528289277, 2.96476634780029, 4.33492777725925, 6.80585097894916,
10.0469893613946, 11.2359910066214, 11.3632449446646, 5.47652057362349,
12.1624004362306, 10.906817159447, 8.07627339240105, 7.51330523102997,
5.16215265151748, 8.55032418997155, 4.32936420681027, 7.70907588066477,
8.42854189722774, 7.1928228994093, 6.45175169812366, 3.78985482198053,
3.54947306301432, 7.16881679031781, 3.07443845739828, 2.76842384012895,
2.78211491127966, 2.63035826591286, 3.4029716238904, 3.79297046444767,
3.53880798407592, 5.43870453261712, 5.07920649228422, 12.9546584619937,
4.02328957639244, 10.3525744201763, 9.64925351685097, 5.46595977775097,
4.05307955253949, 4.07707662227455, 10.6238044923982, 4.28532904283762,
4.33691865638529, 4.43046602675603, 1.84292837586937, 4.49308486235944,
4.5312491956388, 4.79593991740801, 4.67537444232058, 2.41379396626427,
1.6699839123448, 1.89572963263843, 2.22674742100158, 3.48564721285749,
3.8009427060116, 3.43286888385444, 3.90053673711118, 4.29788725585451,
6.16514503593655, 3.11350018022043, 6.52731326633149, 4.3116517707907,
4.11635931501665, 4.11499820440921, 16.7599209530675, 14.6265070254832,
1.49314782562134, 1.98994667463885, 2.92130264154463, 2.70838250336083,
3.34117328175, 3.91770992600132, 2.80208780496034, 2.00191633504495,
4.12918103670829, 1.28656939963522, 1.38863966287248, 1.78543227774678,
2.3555491091684, 2.44967910877932, 3.06488070551261, 4.37519081404913,
5.71719662541664, 6.75682459734961, 1.82957832972716, 4.76407261260154,
5.79230215496683, 6.08921418184509, 16.635224158981, 16.3724225330387,
12.773133419787, 1.87266595478174, 2.07424096118467, 2.96355741615362,
2.68792506933465, 2.23337088010038, 3.34812977863271, 4.07483120227904,
1.71875921804878, 1.71002003692606, 0.858766984261838, 1.38836165005552,
1.8415780261283, 2.79509249040873, 3.89521695832594, 6.12662970318769,
7.14522432244917, 7.32755528428401, 5.41117560909515, 1.50827431411436,
4.77597939698993, 6.13393213534125, 11.7013078259801, 15.1212970305127,
15.8674028990548, 13.9693348877488, 1.52007871257504, 1.84876171232931,
1.30120540757862, 1.12892646601196, 1.07047177886132, 1.32716436312834,
3.10876495992507, 1.75807766831746, 0.914497649253801, 1.12047329941134,
1.43622641814638, 2.12006520012993, 2.88988393073478, 3.51764448501451,
5.13344985378897, 7.05701577117932, 7.18415445216388, 4.5821021978293,
1.66349639592564, 4.47536325758739, 7.05855758484088, 9.97213756310525,
13.1549213491357, 12.537054084307, 12.2475850305256, 1.26961607952348,
0.964343386261585, 0.747461361797493, 0.702539557294478, 0.99492613835112,
1.84288858917705, 1.34486121041946, 2.19465733527654, 1.14554324029827,
1.29950059741933, 1.84835524499147, 2.90217058598644, 3.40877391353338,
4.05446746291369, 4.54573766784205, 5.2530824394743, 3.88147601459954,
3.23835887254304, 2.27552016157486, 3.82304504413186, 6.03003614245222,
6.2407200878979, 6.97460543977307, 8.72201215747591, 9.43442067857835,
2.42403203554782, 1.57288193401563, 1.00546480164572, 0.785258620844128,
0.659835868225952, 1.18874246318751, 0.951280184150778
)), class = "data.frame", row.names = c(
NA,
-300L
))
转化为sf
input_sf <- st_as_sf(input_coords, coords = c("longitud", "latitud"), crs = 4326)
为 st_rasterize
stars
对象
input_template <- st_as_stars(st_bbox(input_sf), dx = 2.5, dy = 2.5)
input_stars <- st_rasterize(input_sf, input_template)
最后,用tmap绘图
tm_shape(input_stars) +
tm_raster(n = 10, legend.show = FALSE, palette = "viridis", contrast = c(0.1, 0.9)) +
tm_shape(us_states) +
tm_borders(lwd = 2, col = "darkgrey")
由 reprex package (v0.3.0)
于 2020-10-13 创建编辑 您需要为网格添加以下代码:
tm_shape(input_stars) +
tm_raster(n = 10, legend.show = FALSE, palette = "viridis", contrast = c(0.1, 0.9)) +
tm_shape(us_states) +
tm_borders(lwd = 2, col = "darkgrey") +
tm_grid()
由 reprex package (v0.3.0)
于 2020-10-14 创建