简体   繁体   中英

How to add "labels" and "value" arguments with highcharter

I want to specify which column I want as label and value in a pie chart The problem is when I use the function hc_add_series_labels_values() which accept this 2 argument I have no output because seems to be deprecated. The hc_add_series() seems to automaticly the 2 column depending on order, type ... This package is not well documented I couldnt find what I need Thanks

In my example I want to specify the name2 column as label and high as value, how to do that ?

library(dplyr)
library(highcharter)

n <- 5

set.seed(123)

colors <- c("#d35400", "#2980b9", "#2ecc71", "#f1c40f", "#2c3e50", "#7f8c8d")
colors2 <- c("#000004", "#3B0F70", "#8C2981", "#DE4968", "#FE9F6D", "#FCFDBF")


df <- data.frame(x = seq_len(n) - 1) %>% 
  mutate(
    y = 10 + x + 10 * sin(x),
    y = round(y, 1),
    z = (x*y) - median(x*y),
    e = 10 * abs(rnorm(length(x))) + 2,
    e = round(e, 1),
    low = y - e,
    high = y + e,
    value = y,
    name = sample(fruit[str_length(fruit) <= 5], size = n),
    color = rep(colors, length.out = n),
    segmentColor = rep(colors2, length.out = n)
  )

df$name2 <- c("mos", "ok", "kk", "jji", "hufg")
##   x    y     z    e  low high value  name   color segmentColor
## 1 0 10.0 -25.6  7.6  2.4 17.6  10.0  plum #d35400      #000004
## 2 1 19.4  -6.2  4.3 15.1 23.7  19.4 lemon #2980b9      #3B0F70
## 3 2 21.1  16.6 17.6  3.5 38.7  21.1 mango #2ecc71      #8C2981
## 4 3 14.4  17.6  2.7 11.7 17.1  14.4  pear #f1c40f      #DE4968
## 5 4  6.4   0.0  3.3  3.1  9.7   6.4 apple #2c3e50      #FE9F6D


  highchart() %>%
    hc_chart(type = "pie") %>% 
    hc_add_series(df, name = "Fruit Consumption", showInLegend = FALSE) 

For People who have same problem you can check this : This package seems to work like ggplot2 , the function hchart do the job with the hcaes argument

 hchart(df, type = "pie", hcaes(name2, high))

Output :

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM