首页 > 解决方案 > 几何文本样式错误

问题描述

我正在尝试使用 和 绘制伦敦地方当局的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")

阴谋

标签: rggplot2tidyverse

解决方案


推荐阅读