使用HighCharter自定义气泡图 [英] Customize bubble map with highcharter

查看:128
本文介绍了使用HighCharter自定义气泡图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮助我在具有highcharter包的发光"应用程序中实现这种出色的jsfiddle吗?
https://jsfiddle.net/BlackLabel/nr1y47a9/

Could someone help me to implement this excellent jsfiddle in a "shiny" application with the highcharter package ?
https://jsfiddle.net/BlackLabel/nr1y47a9/

我开始写这样的东西,但是仍然有一些问题...
结果如下: https://pasteboard.co/J7qWN7v.png

I started writing something like this but there are still some problems ...
Here's the result : https://pasteboard.co/J7qWN7v.png

library(highcharter)
library(httr)
library(dplyr)

getContent <- function(url) {
  content(GET(url))
}
world <- getContent("https://cdn.jsdelivr.net/gh/highcharts/highcharts@v7.0.0/samples/data/world-population.json")

mapdata <- get_data_from_map(download_map_data("custom/world"))

hcmap("custom/world", showInLegend = FALSE) %>% 
  hc_add_series(name = "Countries", color = '#E0E0E0') %>%
  hc_add_series(data= world,type = "mapbubble", name = "Population", joinBy = c("iso-a3", "code3"), color= '#E0E0E0',
                minSize = 4, maxSize = "12%",
                tooltip = list(pointFormat = '{point.properties.hc-a2}: {point.z} thousands')) %>%
  hc_colorAxis(
    dataClasses = color_classes(c(0, 50000, 100000, 500000),
                                colors = c("green","#81c784","#43a047","#1b5e20")#,
                                # names = c("sg","tf","qsd")
    )) %>% 
  hc_legend(title = list(text = "Mon titre"),
            bubbleLegend = list(
              enabled = TRUE,
              borderColor = '#000000',
              borderWidth = 3,
              color = '#8bbc21',
              connectorColor = '#000000'
            ),
            align = "bottom", layout = "horizontal",
            verticalAlign = "bottom",
            floating = TRUE ,valueDecimals = 0,
            symbolHeight = 11, symbolWidth = 11, symbolRadius = 0,
            backgroundColor='#E0E0E8') %>% 
  hc_mapNavigation(enabled = TRUE) %>% 
  hc_exporting(enabled = TRUE) 

非常感谢!

推荐答案

在这里,只有bubbleLegend(在注释#中)不起作用(在地图上显示3次)

Here's where I am, only the bubbleLegend (in comments #) doesn't work (it is displayed 3 times on the map)

mydf <- data.frame(
          lat = c(-7.1871, 36.95733, 17.9356, -20.4379, 30.2496, -54.9593,
                 18.0365, 17.9688, 18, 18.005, 17.9538),
          lon = c(129.3989, -121.576, -66.6961, -68.773, 138.6162, -128.3548,
                 -66.8143, -66.9705, -66.7603, -66.7765, -66.8265),
          z = c(4.5, 2.77, 4.1, 5.2, 4.5, 5.1, 2.52, 3.7, 2.68, 2.71, 2.88),
          part = c(10,15,8,20,30,12,5,17,21,9,11)
)

mydf <- mydf %>% 
  mutate(color = case_when(
    part < 10 ~ "red",
    part < 20 ~ "green",
    TRUE ~ "blue"
  ))
hcmap() %>% 
  hc_add_series(data = mydf, type = "mapbubble", name = "EarthQuake", maxSize = '12%') %>% 
  hc_tooltip(useHTML = T,headerFormat='',pointFormat = paste('Location :{point.place}<br> Part: {point.part} <br> Magnitude : {point.z}')) %>% 
  hc_legend(enabled = TRUE,
            title = list(text = "Mon titre"),
            # bubbleLegend = list(
            #   enabled = TRUE,
            #   borderColor = '#000000',
            #   borderWidth = 3,
            #   color = '#8bbc21',
            #   connectorColor = '#000000'
            # ),
            align = "bottom", layout = "horizontal",
            floating = TRUE ,valueDecimals = 0,
            symbolHeight = 11, symbolWidth = 11, symbolRadius = 0) %>%
  hc_colorAxis(
    dataClasses = color_classes(breaks = c(0, 10, 20, 100),
                                colors = c("red","green","blue")
    )) %>% 
  hc_title(text = "Global Seismic Activity") %>% 
  hc_mapNavigation(enabled = T)%>% 
  hc_exporting(enabled = TRUE) 

这篇关于使用HighCharter自定义气泡图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆