0

你好。我正在为我的数据使用“rworldmap”包。一切都运行良好,唯一的问题与编织 html 格式有关。html 输出不显示地图。我在 html 输出中有其他图表。他们的图表(地图)没有 rworldmap。

笔记:

1- 我需要将我的数据作为 html 文件上传。

2- 由于我的数据,我正在使用 library(rworldmap)。

我不知道为什么 knit (html) 没有在我的文件中显示地图。有什么建议吗?

我的html文件格式:

---
output:
  html_document:
    toc: true
    code_folding: show
    toc_float: 
        collapsed: false
        smooth_scroll: true
    number_sections: true
  pdf_document: default
  word_document: default
---

开始:

library(rworldmap)
str(data)

 Country: chr  "ALBANIA" "ALBANIA" "ALBANIA" "ALBANIA" 
 var1: Factor w/ 2 levels "0","1": 1 1 1 1 1 1 1 1 1 1 
 var2: Factor w/ 2 levels "0","1": 1 1 1 1 1 1 1 1 1 1 
 var3: Factor w/ 2 levels "0","1": 1 2 2 2 2 2 2 2 2 2 

桌子:

Country   var1   var2   var3   n   Perc
ALBANIA     1      1      1    1   0.075
TURKEY      1      1      1    18   1.35
GERMANY     1      1      0    3    0.22
...

n 是频率

rworldmap 代码:

dev.new(width=20, height=20)
summary_probn<-count(data, Country, 
var1,var3, 
var2)
diss_c<- subset(summary_probn, var1 =="1")
#table<-table(diss_c)#frequency
#proptable<- prop.table(table(diss_c))#Cumulative frequency
#cbind(table, proptable)
diss_c$Perc <- diss_c$n / sum(diss_c$n) * 100
diss_cc<- subset(diss_c, var1 =="1") 
diss_cj <- subset(diss_cc, var2 =="1")

数据类似于以下输出:

地图

mapped_data2 <- joinCountryData2Map(diss_cj, joinCode = "NAME", 
nameJoinColumn = "Country")
par(mai=c(1,0,0.8,2),xaxs="i",yaxs="i")
mapParams <- mapCountryData(mapped_data2, nameColumnToPlot = "Perc", 
catMethod="fixedWidth",  addLegend=FALSE, mapTitle="Europe", mapRegion = "europe")
do.call(addMapLegend ,c(mapParams ,legendLabels="all",legendWidth=1,legendIntervals="data", legendMar = 3, labelFontSize = 1))
#do.call( addMapLegend, c(mapParams, legendWidth=1.5, legendMar = 2, legendLabels="all"))
colourPalette <- c('white','green','red','yellow','blue','black')
4

1 回答 1

0

我找到了这个问题的答案。我在我的 rmarkdown 文件中定义了这个特性:“dev.new(width=20, height=20)”。当我删除它时,“rworldmap 输出”出现在 html 文件中。

于 2018-08-26T20:57:26.823 回答