Is it possible to include maplines in highcharter

2019-05-24 13:56发布

问题:

I'd like to use one set of borderColor and width values for counties and another set for state lines in highcharter as done in this jsfiddle link.

series: [{
            mapData: countiesMap,
            data: data,
            joinBy: ['hc-key', 'code'],
            name: 'Unemployment rate',
            tooltip: {
                valueSuffix: '%'
            },
            borderWidth: 0.5,
            states: {
                hover: {
                    color: '#bada55'
                }
            }
        }, {
            type: 'mapline',
            name: 'State borders',
            data: [lines[0]],
            color: 'white'
        }, {
            type: 'mapline',
            name: 'Separator',
            data: [lines[1]],
            color: 'gray'
        }]

However, I don't understand the data structure and I don't see how the highcharter api allows this to be done. Is this kind of map possible? My first instinct was to add a polygon layer without fill for state borders but this doesn't seem to be the approach to use in highmaps/highcharts.

The effect I'm after is shown here. Bold state borders with lighter county borders. Sorry, not enough reputation to embed images.

回答1:

Basically this is same answer by Roco, but is using highcharter.

live: http://rpubs.com/jbkunst/is-it-possible-to-include-maplines-in-highcharter-maps

code:

library("highcharter")
library("viridisLite")
library("dplyr")

data(unemployment)
data(uscountygeojson)
data(usgeojson)
dclass <- data_frame(from = seq(0, 10, by = 2),
                     to = c(seq(2, 10, by = 2), 50),
                     color = substring(viridis(length(from), option = "C"), 0, 7))
dclass <- list.parse3(dclass)
highchart(type = "map") %>% 
  hc_add_series_map(uscountygeojson, unemployment, value = "value", joinBy = "code",
                    lineWidth = 0.5, color = hex_to_rgba("#000000", 0.75)) %>% 
  hc_add_series(data = uscountygeojson, type = "mapline",
                lineWidth = 2, color = hex_to_rgba("#000000", 0.75)) %>% 
  hc_colorAxis(dataClasses = dclass)

Hope it helps.

Thanks for use the package!



回答2:

If you want to change the width of the borders, you would normally do that with viaborderWidth property, like you already do for the county lines.

Your state lines are of different type, they belong to the mapline type. For this type, the documentation specifies that you need to use lineWidth rather than borderWidth. This is what you need to change:

{
  type: 'mapline',
  name: 'State borders',
  data: [lines[0]],
  color: 'black',
  lineWidth: 4
}

This is an example of how I changed your initial JSFiddle to make the state lines much thicker than the county lines: JSFiddle here



标签: r highcharts