R - 将点添加到英国地方当局等值线图 ggplot
R - adding dots to a UK Local Authority choropleth map ggplot
我在 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")
Map with point in the wrong location
因为你的地图数据mymap
是crs(坐标参考系统)OSGB 1936 / 英国国家电网格式任意点在GPS(纬度,经度)格式必须翻译。
例如伦敦 51.52756, -0.257844(GPS WGS84 坐标)转换为 520948.75443717, 182398.33790064(使用 OSTN15 转换的 OSGB36 网格参考)。
- 在你的图中使用数据:
mypoint <- data.frame(lat=520948.75443717,long=182398.33790064)
ggplot() +
geom_sf( data=mymap ) +
geom_point( data=mypoint, aes(lat, long, size=200) )
我在 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")
Map with point in the wrong location
因为你的地图数据mymap
是crs(坐标参考系统)OSGB 1936 / 英国国家电网格式任意点在GPS(纬度,经度)格式必须翻译。
例如伦敦 51.52756, -0.257844(GPS WGS84 坐标)转换为 520948.75443717, 182398.33790064(使用 OSTN15 转换的 OSGB36 网格参考)。
- 在你的图中使用数据:
mypoint <- data.frame(lat=520948.75443717,long=182398.33790064)
ggplot() +
geom_sf( data=mymap ) +
geom_point( data=mypoint, aes(lat, long, size=200) )