使用闪亮R中的Highcharts重命名饼图中的“切片”

时间:2017-06-07 16:13:06

标签: r highcharts shiny

使用下面的代码使用Highcharts在闪亮的R界面中制作饼图,但无法命名切片。我使用了从我的app文件夹中以csv格式存储的数据集。

  output$Hist<-renderHighchart({

        data<-read.csv(paste0(getwd(),"/data.csv"),header=TRUE,stringsAsFactors=FALSE)
        highchart() %>%
          hc_chart(type = "pie") %>% 
          hc_plotOptions(
            series = list(showInLegend = TRUE)
          ) %>% 
          hc_add_series(data =  data$Count, name = data$X) %>%
    hc_tooltip(valueDecimals = 0,
                     pointFormat = "Count: {point.y}") %>%
 hc_legend(enabled = TRUE)%>%

图表图片: this is the chart output

sample data

1 个答案:

答案 0 :(得分:1)

像这样:

library(highcharter)
data <- data.frame(X=c("name1","name2"),Count =c(20,30))
highchart() %>%
hc_add_series_labels_values(data$X, data$Count, name = "Pie",colorByPoint = TRUE, type = "pie")

enter image description here