我有一个关于geom_barggplot2包中填充字段的问题.
我想用变量填充我的geom_bar(在下一个示例中调用变量var_fill),但是geom_plot使用另一个变量(clarity在示例中调用)来命令.
我怎样才能做到这一点?
非常感谢你!
这个例子:
rm(list=ls())
set.seed(1)
library(dplyr)
data_ex <- diamonds %>%
group_by(cut, clarity) %>%
summarise(count = n()) %>%
ungroup() %>%
mutate(var_fill= LETTERS[sample.int(3, 40, replace = TRUE)])
head(data_ex)
# A tibble: 6 x 4
cut clarity count var_fill
<ord> <ord> <int> <chr>
1 Fair I1 210 A
2 Fair SI2 466 B
3 Fair SI1 408 B
4 Fair VS2 261 C
5 Fair VS1 170 A
6 Fair VVS2 69 C …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 Lambert 93 (st_transform(2154)) 中制作传单地图,包括: 1. 多边形(法国) 2. 栅格图层(欧洲)
我不明白为什么下面的代码不起作用。
library(leaflet)
library(tidyverse)
library(sf)
library(grid)
library(fasterize)
library(cartography)
library(mapview)
sf_europe <- cartography::nuts0.spdf %>% st_as_sf %>% mutate(num=ifelse(id=="FR",1,0)) %>% st_transform(2154)
r <- raster(sf_europe, res = 10000)
r <- fasterize(sf_europe, r, field="num",background = 2)
epsg_affichage <- leafletCRS(crsClass = 'L.Proj.CRS', code = 'EPSG:2154',
proj4def = "+proj=lcc +lat_1=49 +lat_2=44 +lat_0=46.5 +lon_0=3 +x_0=700000 +y_0=6600000 +ellps=GRS80 +units=m +no_defs",
resolutions = c(65536, 32768, 16384, 8192, 4096, 2048)
)
sf_france_4326 <- sf_europe %>% filter(id=="FR") %>% st_transform(4326)
leaflet(options =
leafletOptions(maxZoom = 5, …Run Code Online (Sandbox Code Playgroud)