第 8 章 图表拓展

8.1 水球图liquidfill

ecomfe/echarts-liquidfill

# https://github.com/ecomfe/echarts-liquidfill
lf_opt = list(
  series = list(
    list(
      type = 'liquidFill',
      radius = '90%',
      label = list(
        normal = list(
          formatter = '占比 \n 60%',
          textStyle = list(
            fontSize = 60
          )
        )
      ),
      data = c(0.6, 0.5, 0.4)
    ))
)
echart(lf_opt)
# # 或者通过下列方式
# echart() %>%
#   ec_add_series(
#     data = c(0.6, 0.5, 0.4),
#     type = 'liquidFill',
#     radius = '90%',
#     label = list(
#       normal = list(
#         formatter = '占比 \n 60%',
#         textStyle = list(
#           fontSize = 60
#         )
#       )
#     ))

8.2 字符云wordcloud

ecomfe/echarts-wordcloud

library(jiebaR)
file <- read_lines("data/2017年中央政府工作报告.txt")
word <- segment(file, worker())
word_freq <- freq(word)
write.csv(word_freq, "data/word_freq.csv", row.names = FALSE)
word_freq <- read.csv("data/word_freq.csv") %>% 
  filter(freq > 20, stringi::stri_length(char) > 1)
word_freq <- word_freq[order(word_freq$freq, decreasing=TRUE),]

echart() %>%
  ec_add_series(
    type = 'wordCloud',
    data = word_freq, mapping = ecaes(name = char, value = freq)
  )