echarter入门

devtools::install_github("cardiomoon/moonBook")
devtools::install_github("cardiomoon/webr")
require(ggplot2)
require(moonBook)
require(webr)

devtools::install_github("jeevanyue/echarter")
library(echarter)
library(tidyverse)
dataStyle <- list(
  normal = list(
    label = list(show = FALSE),
    labelLine = list(show = FALSE)
  )
)
placeHolderStyle <- list(
  normal = list(
    color ='rgba(0, 0, 0, 0)',
    label = list(show = FALSE),
    labelLine = list(show = FALSE)
  ),
  emphasis = list(
    color = 'rgba(255,0,0,0)'
  )
)
#修改主题
echart(theme = 'shine')%>%
  ec_title(
    text = '你幸福吗?',
    x = 'center',
    y = 'center',
    itemGap = 20,
    textStyle = list(
      color = 'rgba(30,144,255,0.8)',
      fontFamily = '微软雅黑',
      fontSize = 15,
      fontWeight = 'bolder'
    )
  ) %>%
  ec_tooltip(
    show = TRUE, trigger = 'item',
    formatter = "{a} <br/>{b} = {c} ({d}%)") %>%
  ec_legend(
    orient = 'vertical',
    left = '50%',
    top = '20%',
    itemGap = 10,
    data = c('43.40%的人从眼科医生获得','36.55%的人从其它白内障患者获得','9.64%的人从媒体获得','5.95%的人从其他获得','4.46%的人从非眼科医生获得')
  ) %>%
  ec_add_series(
    name = '1',
    data = list(
      list(value = 43.40, name = "43.40%的人从眼科医生获得"),
      list(value = 56.60, itemStyle = placeHolderStyle)),
    type = 'pie', clockWise = FALSE,
    itemStyle = dataStyle,
    radius = list(125, 150)) %>%
  ec_add_series(
    name = '2',
    data = list(
      list(value = 36.55, name = "36.55%的人从其它白内障患者获得"),
      list(value = 63.45, itemStyle = placeHolderStyle)),
    type = 'pie', clockWise = FALSE,
    itemStyle = dataStyle,
    radius = list(100, 125)) %>%
  ec_add_series(
    name = '3',
    data = list(
      list(value = 9.64, name = "9.64%的人从媒体获得"),
      list(value = 90.36, itemStyle = placeHolderStyle)),
    type = 'pie', clockWise = FALSE,
    itemStyle = dataStyle,
    radius = list(75, 100)) %>%
  ec_add_series(
    name = '4',
    data = list(
      list(value = 5.95, name = "5.95%的人从其他获得"),
      list(value = 99.05, itemStyle = placeHolderStyle)),
    type = 'pie', clockWise = FALSE,
    itemStyle = dataStyle,
    radius = list(50, 75)) %>%
  ec_add_series(
    name = '5',
    data = list(
      list(value = 4.46, name = "4.46%的人从非眼科医生获得"),
      list(value = 95.54, itemStyle = placeHolderStyle)),
    type = 'pie', clockWise = FALSE,
    itemStyle = dataStyle,
    radius = list(25, 50))


shanghai_geoJson <- jsonlite::read_json("https://raw.githubusercontent.com/ecomfe/echarts-www/master/asset/map/json/province/shanghai.json")
gansu_geoJson <- jsonlite::read_json("https://raw.githubusercontent.com/ecomfe/echarts-www/master/asset/map/json/province/gansu.json")
shanghai_dat <- data.frame(
  name = c("崇明区","静安区","宝山区","嘉定区","青浦区","虹口区","杨浦区","黄浦区","卢湾区","长宁区","浦东新区","松江区","金山区","奉贤区","普陀区","闵行区","徐汇区"),
  n = round(runif(17,1,100),0), stringsAsFactors = FALSE)

echart() %>%
  ec_registerMap("shanghai", shanghai_geoJson) %>%
  ec_add_series(
    type = 'map', mapType = 'shanghai',
    data = shanghai_dat,
    mapping = ecaes(name = name, value = n),
    label = list(
      normal = list(show = FALSE),
      emphasis = list(show = FALSE))) %>%
  ec_visualMap(
    calculable = TRUE,
    min = 0, max = 100, text = c("高", "低"),
    color = c('#eac736','#50a3ba')) %>%
  ec_tooltip(trigger = 'item',formatter = '{b}: {c}')

评论

此博客中的热门博文

V2ray websocket(ws)+tls+nginx分流

Rstudio 使用代理