MultiBarChart与HighCharter在闪亮的应用程序

问题描述 投票:0回答:1

有没有办法在Shiny app中使用highcharter包绘制这样的图形?

https://www.highcharts.com/demo/column-stacked-and-grouped

这是我的数据帧:

names <- c("Sr. Blue","Sr. Green","Sr. Brown","Sr. Yellow","Sr. Purple","Sr. Fish","Sr. Greek","Sr. Red","Sr. Dark")
names <- names[rep(seq_len(length(names)), each=5)]
teachers <- data.frame(name = names, age = rep(c("0-4","4-9","9-15","15-20","+20"),9),students = sample(1:50,45))

目标是向学生显示按年龄分组的姓名。

r highcharts shiny r-highcharter
1个回答
0
投票

以下是如何在Highcharts(Highcharter)和Shiny中绘制堆积柱图的示例:

library(shiny)
library(highcharter)
ui <- fluidPage(
  h1("Highcharts Shiny stacked column demo"),
  fluidRow(
    column(width = 12, highchartOutput("hcontainer",height = "500px"))
  )
)
server = function(input, output) {
  output$hcontainer <- renderHighchart({
    hc <- highchart() %>%
      hc_chart(type = 'column') %>%
      hc_xAxis(categories = c('Apples', 'Oranges', 'Pears', 'Grapes', 'Bananas')) %>%
      hc_plotOptions(series = list(stacking = 'normal')) %>%
      hc_add_series(
        name = 'John',
        data = list(5, 3, 4, 7, 2),
        stack = 'male'
      ) %>%
      hc_add_series(
        name = 'Joe',
        data = list(3, 4, 4, 2, 5),
        stack = 'male'
      ) %>%
      hc_add_series(
        name = 'Jane',
        data = list(2, 5, 6, 2, 1),
        stack = 'female'
      ) %>%
      hc_add_series(
        name = 'Janet',
        data = list(3, 0, 4, 4, 3),
        stack = 'female'
      )
    hc
  })
}
shinyApp(ui = ui, server = server)

我不是R开发人员所以我不知道你的数据究竟是什么样的,但是如果你给我更多关于x类别,系列名称和y值的详细信息,我会尝试帮助你完成你的图表并编辑我的答案。

这是上面图表的纯JS代码:https://jsfiddle.net/BlackLabel/wgthu2L5

一些API参考可能会有用:https://api.highcharts.com/highcharts/plotOptions.series.stacking https://api.highcharts.com/highcharts/series.column.stack https://api.highcharts.com/highcharts/xAxis.categories

© www.soinside.com 2019 - 2024. All rights reserved.