我在 R 中制作了一個 Choropleth 地圖,它根據處于燃料貧困中的家庭的百分比為地方當局提供陰影。
#converts file into a readable format
options(scipen = 999)
#create a data frame from imported CSV file
mydata <- readr::read_csv("/Users/Desktop/R/Map/Fuel_Poverty.csv")
#import shape file
mymap <-st_read("Local_Authority_Districts__December_2019__Boundaries_UK_BUC.shp", stringsAsFactors = FALSE)
#joins map shape file to local authority data csv
map_and_data <- inner_join(mymap,mydata)
#displays structure of object
str(map_and_data)
#creates a plot
ggplot(map_and_data)
geom_sf(aes(fill = Fuel_Poverty_Percentage),lwd = 0.1)
theme_void()
scale_fill_gradient2(low = "#a50026", high = "#005abb", midpoint = 170, na.value = "#808080")
我現在想在一些點上分層,這些點將對應于特定位置,可能以郵政成本或緯度和經度值的形式。我已經嘗試過幾個教程,但無論我設定的經度和緯度值如何,似乎都會讓點出現在左下角?
(sites <- data.frame(lat = c(54.7), long = c(-1.27)))
#creates a plot
ggplot(map_and_data)
geom_sf(aes(fill = Fuel_Poverty),lwd = 0.1) # lwd = 0.1 is line thickness, 1.5 @5000 pixels to save well
geom_point(data = sites, aes(x = long, y = lat), size = 3, shape = 21, fill = "red")
theme_void() #this takes out the background
scale_fill_gradient2(low = "#005abb", high = "#a50026", midpoint = 12, na.value = "#808080")

轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/358901.html
上一篇:如何在r中繪制偏斜資料和正常資料
