我想使用mapview可视化下面的空间数据框(sf对象),并在地图和图例上使用特定的颜色。将zcol
参数分配给“商品”将显示所有值,但是当我使用col.regions
参数指定一组自定义的颜色值时,它会打乱我指定的顺序(即标有氧化铝和锑的位置)粉红色,钴为蓝色)。如何更改我的mapview调用,以便这些一对一的映射以及我的数据值和颜色选择?
library(mapview); library(tibble)
reprexdf <- structure(list(Commodity = c("Alumina", "Antimony", "Bauxite",
"Chromite", "Coal", "Cobalt", "Copper", "Diamonds", "Gold", "Graphite",
"Ilmenite", "Iron Ore", "Lanthanides", "Lead", "Lithium", "Manganese",
"Molybdenum", "Nickel", "Palladium", "Phosphate", "Platinum",
"Potash", "Rutile", "Scandium", "Silver", "Tantalum", "Tin",
"Titanium", "Tungsten", "U3O8", "Vanadium", "Zinc"), geometry = structure(list(
structure(c(74.1867018689986, 43.1980200148667), class = c("XY",
"POINT", "sfg")), structure(c(71.7552595131403, 39.6561200773791
), class = c("XY", "POINT", "sfg")), structure(c(68.4892405701349,
52.7147846055392), class = c("XY", "POINT", "sfg")), structure(c(32.0340206057459,
38.6167768843658), class = c("XY", "POINT", "sfg")), structure(c(17.7734702058381,
51.5204514008904), class = c("XY", "POINT", "sfg")), structure(c(22.2954101440738,
51.2054063543333), class = c("XY", "POINT", "sfg")), structure(c(59.3802911872375,
46.5120764901861), class = c("XY", "POINT", "sfg")), structure(c(30.9448779697714,
62.7866761615543), class = c("XY", "POINT", "sfg")), structure(c(19.6991862079032,
68.0630555165806), class = c("XY", "POINT", "sfg")), structure(c(23.3633810296335,
61.2323113198727), class = c("XY", "POINT", "sfg")), structure(c(22.6936032890073,
64.400202153036), class = c("XY", "POINT", "sfg")), structure(c(16.2933393846649,
41.115478005968), class = c("XY", "POINT", "sfg")), structure(c(74.8921184988305,
53.4147177051134), class = c("XY", "POINT", "sfg")), structure(c(-4.62308734592504,
38.4973852079805), class = c("XY", "POINT", "sfg")), structure(c(-5.55711136406121,
38.7609039997681), class = c("XY", "POINT", "sfg")), structure(c(46.1696365421761,
37.8054777412675), class = c("XY", "POINT", "sfg")), structure(c(69.1338599506306,
45.1046447967609), class = c("XY", "POINT", "sfg")), structure(c(26.0266877752458,
61.6213181277374), class = c("XY", "POINT", "sfg")), structure(c(14.678433940652,
65.8316734439636), class = c("XY", "POINT", "sfg")), structure(c(64.8626780282562,
36.2120365056795), class = c("XY", "POINT", "sfg")), structure(c(75.2744534960289,
41.7416342085414), class = c("XY", "POINT", "sfg")), structure(c(7.54172575797454,
54.7804503893017), class = c("XY", "POINT", "sfg")), structure(c(5.35439579518009,
62.2667697053924), class = c("XY", "POINT", "sfg")), structure(c(25.9135045170651,
58.1849810922895), class = c("XY", "POINT", "sfg")), structure(c(8.50142345297422,
58.1222871519439), class = c("XY", "POINT", "sfg")), structure(c(24.8503658161678,
60.0844617435652), class = c("XY", "POINT", "sfg")), structure(c(-8.16011736668124,
38.1627405413439), class = c("XY", "POINT", "sfg")), structure(c(58.4011176975426,
37.8798048427329), class = c("XY", "POINT", "sfg")), structure(c(-9.25666269137908,
41.900952474145), class = c("XY", "POINT", "sfg")), structure(c(63.3159694601457,
39.6821149461387), class = c("XY", "POINT", "sfg")), structure(c(25.5040625781002,
66.628066442373), class = c("XY", "POINT", "sfg")), structure(c(-6.02123775666737,
54.8933062105439), class = c("XY", "POINT", "sfg"))), class = c("sfc_POINT",
"sfc"), precision = 0, bbox = structure(c(xmin = -9.25666269137908,
ymin = 36.2120365056795, xmax = 75.2744534960289, ymax = 68.0630555165806
), class = "bbox"), crs = structure(list(epsg = 4326L, proj4string = "+proj=longlat +datum=WGS84 +no_defs"), class = "crs"), n_empty = 0L)), row.names = c(NA,
-32L), groups = structure(list(Commodity = c("Alumina", "Antimony",
"Bauxite", "Chromite", "Coal", "Cobalt", "Copper", "Diamonds",
"Gold", "Graphite", "Ilmenite", "Iron Ore", "Lanthanides", "Lead",
"Lithium", "Manganese", "Molybdenum", "Nickel", "Palladium",
"Phosphate", "Platinum", "Potash", "Rutile", "Scandium", "Silver",
"Tantalum", "Tin", "Titanium", "Tungsten", "U3O8", "Vanadium",
"Zinc"), .rows = list(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L,
11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L,
23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L)), row.names = c(NA,
-32L), class = c("tbl_df", "tbl", "data.frame")), sf_column = "geometry", agr = structure(c(Commodity = NA_integer_), .Label = c("constant",
"aggregate", "identity"), class = "factor"), class = c("sf",
"grouped_df", "tbl_df", "tbl", "data.frame"))
mapview(reprexdf, zcol = 'Commodity',
col.regions = c("pink", "pink", "#6FB000", "grey90", "black", "blue", "#F8766D", "#00ADFA", "lightgoldenrod4", "grey", "grey90", "grey30", "grey90", "#00C19F", "grey90", "grey90", "grey90", "#00BFC4", "darkslategrey", "#619CFF", "darkslategrey", "grey90", "pink", "pink", "grey80", "pink", "#FF61C3", "pink", "grey90", "green", "pink", "#FF699C"
))