kartenn gentañ, wip

This commit is contained in:
Ewen 2022-11-04 07:05:29 +01:00
parent cfb81d0dab
commit db9ade0eb4
3 changed files with 21 additions and 60 deletions

BIN
res/Agropyron repens.pdf Normal file

Binary file not shown.

View file

@ -1,5 +1,9 @@
library("osmdata")
library("sf")
library(osmdata)
library(sf)
library(magrittr)
library(dplyr)
library(tidyr)
library(ggplot2)
##############################
## Arventennoù
@ -10,7 +14,7 @@ setwd(dirname(dirname(source_path)))
## Kemer an data
# An harzoù
if (!file.exists("./tmp/kumunioù.RData")) {
if (!file.exists("./tmp/kumuniou.RData")) {
kumuniou_22 <- opq(bbox="Côtes-d'Armor") %>%
add_osm_feature(key = 'boundary', value = 'administrative') %>%
add_osm_feature(key = 'admin_level', value = '8') %>%
@ -35,7 +39,7 @@ if (!file.exists("./tmp/kumunioù.RData")) {
filter(grepl("^(22|29|56)", ref.INSEE))
ggplot(municipalities_poly)+
ggplot(kumuniou_poly)+
geom_sf()
@ -52,7 +56,7 @@ if (!file.exists("./tmp/kumunioù.RData")) {
add_osm_feature(key = 'admin_level', value = '6') %>%
osmdata_sf %>% unique_osmdata
dept <- c(dept_22, dept_29, dept_35, dept_44, dept_56) %>%
dept <- c(dept_22, dept_29, dept_56) %>%
unique_osmdata
dept_poly <- dept$osm_multipolygons
@ -64,5 +68,8 @@ if (!file.exists("./tmp/kumunioù.RData")) {
dept, dept_poly,
file = "./tmp/kumuniou.RData")
} else {
load(file = "../roadennoù/kumuniou.RData")
load(file = "./tmp/kumuniou.RData")
}
kumuniou_poly_simple <- st_simplify(kumuniou_poly, preserveTopology = TRUE, dTolerance = 0.001)
dept_poly_simple <- st_simplify(dept_poly, preserveTopology = TRUE, dTolerance = 0.001)

View file

@ -13,7 +13,7 @@ source("./scripts/enporzhiañ.R")
##############################
## Enporzhiañ peadra d'ober ur gartenn
# (harzoù hag all)
# disoc'h = data_osm
# disoc'h = kumuniou, kumuniou_poly, kumuniou_poly_simple, dept, dept_poly, dept_poly_simple
source("./scripts/enporzhiañ_kartenn.R")
@ -23,61 +23,17 @@ source("./scripts/enporzhiañ_kartenn.R")
anv <- "Agropyron repens"
sub_data <- data %>%
filter(anv_latin==anv)
filter(anv_latin==anv) %>%
tidyr::unite(., label, anv_bzg_1, anv_bzg_2, anv_bzg_3, na.rm=TRUE, sep="\n")
data <- merge(municipalities_poly,
data_percentages, by.x="ref.INSEE", by.y="ebssa", all.x=TRUE)
# Rannañ an dregantadoù dre rummad
data$emdroadur_rummad <- cut(data$emdroadur, breaks=c(-0.05, -0.02, -0.01, -0.005, 0, 0.01, 0.02, 0.03, 0.04, 0.12))
data$emdroadur2007_rummad <- cut(data$emdroadur2007_2017, breaks=c(-0.05, -0.02, -0.01, -0.005, 0, 0.01, 0.02, 0.03, 0.04, 0.12))
# Evit gwiriañ: peseurt kumun zo hep emdroadur?
data %>%
filter(is.na(emdroadur))
# => Plevenon ha Sant-Sinforian (poblañs ebet e 1999, nevez krouet int?)
#pdf("./kartenn_dregantad_skolioumamm_publik_prevez_diwan.pdf", width = 25, height = 20)
data_simple <- st_simplify(data, preserveTopology = TRUE, dTolerance = 0.001)
dept_poly_simple <- st_simplify(dept_poly, preserveTopology = TRUE, dTolerance = 0.001)
br <- c(-0.02, -0.01, -0.005, 0, 0.01, 0.02, 0.03, 0.04)
## Diskouez
pdf("../kartenn_emdroadur_poblañs.pdf", width=10, height=7)
p <- ggplot(data=data_simple, aes(fill=emdroadur, text=paste0(name, "\nEmdroadur: ", round(emdroadur, 3)*100, "%")))+
pdf(paste0("./res/", anv, ".pdf"), width=10, height=7)
p <- ggplot(data=kumuniou_poly_simple)+
geom_sf(size=0.1, color="#bfbfbf")+
#scale_fill_manual(values=c("#152a84",
binned_scale(aesthetics="fill", scale_name="stepsn",
palette=function(x) c("#152a84",
"#275da5",
"#00ade2",
"#c6e7f3",
"#f7f4d8",
"#fbea68",
"#f1b85f",
"#e78051",
"#e04c45"),
breaks=br,
limits=c(-0.05, 0.12),
guide="colorsteps",
labels=paste0(br*100, "%"))+
guides(colour=guide_legend("No data", override.aes=list(colour="grey75")))+
ggtitle(paste0("Emdroadur poblañs kumunioù Breizh etre 1999 ha 2017"))+
ggtitle(anv)+
theme_void()+
labs(fill="Feur kresk bloaziek ar boblañs etre 1999 ha 2017")+
guides(fill=guide_colorsteps(title.position="top", ticks=TRUE))+
# Anvioù
geom_label(data=sub_data, alpha=.25, color="black", aes(x=hed, y=led, label=label))+
theme(plot.title = element_text(face = "bold", hjust=0.5, size=12),
legend.position="bottom",
legend.title=element_text(size=10),
@ -85,5 +41,3 @@ p <- ggplot(data=data_simple, aes(fill=emdroadur, text=paste0(name, "\nEmdroadur
legend.key.height=unit(0.1, "inches"))
print(p)
dev.off()
ggplotly(p)