简体   繁体   English

R,rMaps,Datamaps:移动Choropleth地图的图例

[英]R, rMaps, datamaps: Moving the legend of a choropleth map

I'm attempting to center the legend below a choropleth map of the United States ( an example of a generic map similar to what I've created ). 我试图将图例放在美国的Choropleth地图下方( 类似于我创建的通用地图的示例 )。 I'm not very familiar with JS or CSS, but I poked around in the datamaps.all.min.js file located in the R-3.2.1\\library\\rMaps\\libraries\\datamaps\\js directory hoping to be able to locate the tag for the legend and its default values. 我对JS或CSS不太熟悉,但我在R-3.2.1\\library\\rMaps\\libraries\\datamaps\\js目录中的datamaps.all.min.js文件中打了R-3.2.1\\library\\rMaps\\libraries\\datamaps\\js希望能够找到它图例的标签及其默认值。 I found this: 我找到了这个:

.datamaps-legend dt, .datamaps-legend dd { 
  float: left; 
  margin: 0 3px 0 0;

} .datamaps-legend dd {
  width: 20px; 
  margin-right: 6px; 
  border-radius: 3px;

} .datamaps-legend {
  padding-bottom: 20px; 
  z-index: 1001; 
  position: absolute; 
  left: 4px; 
  font-size: 12px; 
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;

}

I changed it to this and included it in my header.html file: 我将其更改为此,并将其包含在header.html文件中:

.datamaps-legend dt, .datamaps-legend dd { 
  float: left; 
  margin: 0 3px 0 0;

} .datamaps-legend dd {
  width: 20px; 
  margin-right: 6px; 
  border-radius: 3px;

} .datamaps-legend {
  padding-bottom: 20px; 
  z-index: 1001; 
  position: absolute; 
  left: 40px; 
  font-size: 10px; 
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;

}

It appears that these changes are either wrong or ineffective possibly because there is some other .css file taking precedence over these instructions. 这些更改似乎是错误的或无效的,可能是因为还有其他一些.css文件优先于这些指令。 Currently, the relevant portion of the map looks like this: 当前,地图的相关部分如下所示:

在此处输入图片说明

The problems include 1) what to me seems like an inexplicable bold and italic treatment of the text edit: fixed that in my .css file and 2) although "position: absolute" , the graphic flows over onto the tables below. 问题包括1)在我看来是对文本 编辑的 一种莫名其妙的粗体和斜体处理 :修复了我的.css文件中的内容,以及2)尽管是"position: absolute" ,但该图形流到了下表中。

You should be able to add some CSS to override the default styles, like so: 您应该能够添加一些CSS来覆盖默认样式,如下所示:

.datamaps-legend {
  position: static;
}

.datamaps-legend dl {
  text-align: center;
  display: inline-block;
}

So what I ended up doing, following the advice of @markmarkoh , was to amend the template script chart.html located in ~\\R-3.2.1\\library\\rCharts\\libraries\\datamaps\\layouts and change the very end of it from 因此,根据@markmarkoh的建议,我最终要做的是修改位于~\\R-3.2.1\\library\\rCharts\\libraries\\datamaps\\layouts的模板脚本chart.html ,并将其结尾更改为

<style>
.datamaps {
  position: relative;
}
</style>

to

<style>
.datamaps {
  position: relative;
  display: inline-block;
  text-align: center;
}
.datamaps-legend {
  position: static;
}

.datamaps-legend dl {
  text-align: center;
  display: inline-block;
}
</style>

then save the modified copy to my working directory and change the template location of the figure like this: 然后将修改后的副本保存到我的工作目录中,并更改图形的模板位置,如下所示:

map1$setTemplate(script = 'chart.html')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM