R-Markdown如何在PDF中仅显示map而不显示所有其他结果的代码



这是我第一次使用R Markdown,我正在尝试编织我的PDF。我想隐藏所有的东西是在控制台除了地图产生。所以我只想要PDF格式的代码和地图。

我尝试使用"message =FALSE,warning=FALSE"但这并不能解决问题。如下图所示,我想从数据

中删除圈出的区域[输入图片描述][1]

library("sp")
library("rgdal")
library("rgeos")
library("tmap")
library("spgwr")

Census.Data <-read.csv("worksheet_data/Southwark/practical_data_Southwark.csv")
# Load the output area shapefiles
Output.Areas<- readOGR("worksheet_data/Southwark/shapefiles", "Southwark_oa11")
# join our census data to the shapefile
OA.Census <- merge(Output.Areas, Census.Data, by.x="OA11CD", by.y="OA")
#Set the coordinate system to the British National Grid
proj4string(OA.Census) <- CRS("+init=epsg:27700")
#Data=polygonshapefile
#Dependent= Dependent variabable of shapefile
#Independent1= Explantory variable 1 
#Independent2= Explantory variable 2

GWR_map <- function(Data,dependent,independent1,independent2){
GWRbandwidth <- gwr.sel(Data[[dependent]] ~ Data[[independent1]] + Data[[independent2]], data= Data, adapt = T)  
GWR.model = gwr(Data[[dependent]] ~ Data[[independent1]] + Data[[independent2]], data= Data, adapt=GWRbandwidth, hatmatrix=TRUE, se.fit=TRUE)
GWR.model
results_GWR.model<-as.data.frame(GWR.model$SDF)
names(results_GWR.model)
GWR.map<- Data
GWR.map@data<- cbind(Data@data, as.matrix(results_GWR.model))

map1<- tm_shape(GWR.map) + tm_fill("localR2", n = 5, style = "quantile",  palette = "Blues")  + tm_layout(frame = TRUE, legend.text.size = 1.2, legend.title.size = 1.5, bg.color = "grey85")
map1
}

GWR_map(OA.Census,"Qualification", "Unemployed", "White_British")

[1]: https://i.stack.imgur.com/EFhLw.png

如果在生成不必要消息的函数中包含verbose=FALSE,可能会有效

在您的情况下,您可以尝试

Output.Areas<- readOGR("worksheet_data/Southwark/shapefiles", "Southwark_oa11", verbose=FALSE)

相关内容

  • 没有找到相关文章

最新更新