博文

目前显示的是 十月, 2021的博文

读写geojson和shp文件

 library(sf) library(tidyverse) 读写geojson shi <- st_read("C:\\Users\\ruiying\\Desktop\\shi.geojson") st_write(shi, "C:\\Users\\ruiying\\Desktop\\shi2.geojson",append=F) 读写json weihai <- st_read("D:\\使用GEOJSON数据绘制地图\\威海市.json") st_write(weihai %>% select(name,adcode),"C:\\Users\\ruiying\\Desktop\\weihai.geojson") st_write(meuse_sf,"weihai.shp") st_write(meuse_sf,"weihai.geojson",append = F) st_write(meuse_sf,"weihai.json",driver = 'GeoJSON',append = F) st_write(meuse_sf,"weihai.gpkg",append = F) test <- st_read('C:\\Users\\ruiying\\Desktop\\shi.geojson')

填充地图

 shi %>%    left_join(shi_df,by=c('市代码'='市代码')) %>%    filter(str_detect(市代码,'^62')) %>%    ggplot()+   geom_sf(aes(fill=bl),size=0.01)+   scale_fill_gradientn(breaks = c(15,30,45),                        colors=c("gray", "yellow", "orange", "red"))

R 分层抽样

 library(sampling) mtcars_order <- mtcars %>% arrange(gear) mtcars_order %>% group_by(gear) %>% summarise(n=n()) smn <- round(prop.table(table(mtcars_order$gear))*10) stratID <- strata(mtcars_order,stratanames='gear',size = smn,method = 'srswor') head(stratID) strat<-getdata(mtcars_order,stratID) library(doBy) mtcars %>% group_by(am,gear) %>% summarise(n=n()) mtcars %>% group_by(am) %>% summarise(n=n()) sampleBy(formula = ~ iris$Species,frac=0.1,data=iris) sample_by(mtcars,formula = ~am+gear,frac = 0.2)