是否有一种方法可以在Shiny应用程序中使用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))
目标是显示按年龄分组的学生姓名。
答案 0 :(得分: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