参考:https://www.yuque.com/docs/share/df2b42d4-bc1f-4596-bc03-08cf3838171d

环境准备

  1. # 环境准备
  2. options("repos"=c(CRAN="https://mirrors.ustc.edu.cn/CRAN/"))
  3. options(BioC_mirror="http://mirrors.ustc.edu.cn/bioc/")
  4. install.packages("echarts4r")
  5. library(echarts4r)
  6. library(dplyr)

示例数据构建

  1. df <- data.frame(
  2. event = c("A3SS","A5SS","SE","RI","MXE"),
  3. count = c(10, 24, 40, 17, 9))

绘图

  1. # 绘图
  2. df %>%
  3. e_chart(event) %>%
  4. e_pie(count, radius = c("30%", "60%"),
  5. timeline = T,legend =F,name="Event and Percent") %>%
  6. e_labels(
  7. position = "outside",
  8. labelLine = list(length = 30),
  9. formatter = "{a|{a}}{abg|}\n{hr|}\n {b|{b}:}{c} {per|{d}%}",
  10. backgroundColor = "#F6F8FC",
  11. borderColor = "#8C8D8E",
  12. borderWidth = 1,
  13. borderRadius = 4,
  14. rich = list(
  15. a = list(
  16. color = "#6E7079",
  17. lineHeight = 22,
  18. align = "center"
  19. ),
  20. hr = list(
  21. borderColor = "#8C8D8E",
  22. width = "100%",
  23. borderWidth = 1,
  24. height = 0
  25. ),
  26. b = list(
  27. color = "#4C5058",
  28. fontSize = 14,
  29. fontWeight = "bold",
  30. lineHeight = 33
  31. ),
  32. per = list(
  33. color = "#fff",
  34. backgroundColor = "#4C5058",
  35. padding = c(3, 4),
  36. borderRadius = 4)))%>%
  37. e_toolbox_feature(feature = c("saveAsImage")) #在Plots右上角添加了个下载png按钮