r - 几何文本样式错误
问题描述
我正在尝试使用 和 绘制伦敦地方当局的tidyverse
排放sf
数据tidyverse
。我已经使用 声明了一些文本样式geom_text
,但绘图未显示不正确的样式。我希望这可能是微不足道的。
library(readr)
library(sf)
library(tidyverse)
library(cowplot)
emissions_london <- read_csv(("boroughEmissions.csv"))
london_sf <-
st_read("statistical-gis-boundaries-london/ESRI/London_Borough_Excluding_MHW.shp") %>%
st_as_sf(london_sf)
london_emissions_sf <- merge(emissions_london, london_sf,
by = c("NAME"))
london_emissions_sf_2018 <-
subset(
london_emissions_sf,
Year == 2018,
select = c(
"NAME",
"Domestic Total",
"Industry and Commercial Total",
"Transport Total",
"LULUCF Net Emissions",
"Grand Total"
)
)
london_emissions_sf_2018_long <- london_emissions_sf_2018 %>%
pivot_longer(!NAME, names_to = "emissions", values_to = "count")
london_emissions_sf_2018_long_sf <-
merge(london_emissions_sf_2018_long, london_sf,
by = c("NAME"))
london_emissions_sf_2018_long_sf <- st_as_sf(london_emissions_sf_2018_long_sf)
max <- london_emissions_sf_2018_long %>%
group_by(emissions) %>%
filter(count == max(count))
max <- merge(max, london_sf,
by = c("NAME"))
max <- st_as_sf(max)
ggplot(london_emissions_sf_2018_long_sf) +
geom_sf(aes(fill = emissions, alpha = count), color = NA) +
geom_sf(data = max, color = NA, fill = "white") +
geom_text(
data = london_emissions_sf_2018_long_sf,
x = -140,
y = -55,
aes(label = toupper(emissions), color = emissions),
check_overlap = T,
angle = 90,
size = 35
) +
facet_wrap(~ emissions, ncol = 5) +
theme_void() +
theme(
strip.background = element_blank(),
legend.position = "none",
plot.background = element_rect(fill = "grey10", color = NA),
plot.margin = unit(c(1, 1, 1, 1), "cm"),
plot.title = element_text(
color = "white",
hjust = .5,
size = 40
),
plot.subtitle = element_text(
color = "grey80",
hjust = .5,
face = "italic"
)
) +
scale_alpha(range = c(0.05, 1)) +
scale_fill_manual(values = c("honeydew1",
"lavenderblush1",
"navajowhite1",
"black",
"olivedrab1")) +
scale_color_manual(values = c("honeydew1",
"lavenderblush1",
"navajowhite1",
'black',
"olivedrab1")) +
labs(title = "London Local Authority 2018 Emissions",
subtitle = "\"Which LA's have the greatest emissions per sector?\"\n\n")
解决方案
推荐阅读
- c++ - 编写一个程序来运行 2 个进程并在第一个运行 ls 并在另一个运行 ps
- javascript - 如何在函数之外使用变量 - javascript
- node.js - Jest Mock FS 文件流
- postgresql - Postgres中的唯一部分约束?
- typescript - 在“{}”类型上找不到带有“数字”类型参数的索引签名 - Typescript 编译器错误
- matlab - Matlab 中的 UI 以获取要在脚本中使用的输入
- javascript - 如何使用github api来关注api帮助认证用户关注他人
- java - 通过 protobuf CodedOutputStream 和 CodedInputStream 从 java 中的套接字写入和读取
- python - Discord.py - 如何将特定服务器的数据保存在 .json 中?
- r - R - 基于另一列改变列