全部,尝试使用highchart()函数和add_series-list构建堆积柱形图 . 使用:Highcharter stacked column groupings not using hchart()
大多数情况下,但是当我浏览高级代码时,我最终得到的结果是:正确主题,正确 Headers 和OrderTypes似乎被考虑在内 . 但是,我以无数据显示结束 . 试图简化并删除第二个列表 . 这是我有的:
orderTypeBar <- monthSummary %>%
group_by(OrderType) %>%
do(monthSummary = list_parse2(.[, c('monthGroup', 'Total')])) %>%
rename(name = OrderType) %>%
mutate(OrderType = 'column') %>%
list_parse()
highchart() %>%
hc_add_theme(hc_theme_ffx()) %>%
hc_title(text = "Revenue By Order Type") %>%
hc_add_series_list(orderTypeBar) %>%
hc_xAxis(categories = monthSummary$monthGroup) %>%
hc_plotOptions(series=list(stacking='normal'))
Summary表使用以下dplyr转换构建 .
monthSummary <- data %>%
group_by(monthGroup, OrderType) %>%
summarise(CustomerNumber = n()
, SalesFulfilled = sum(Fulfilled)
, SalesFreight = sum(Freight)
, SalesTax = sum(Tax)
, ServiceLabor = sum(LaborAmount)
, ServiceMaterials = sum(MaterialCost)
, Total = sum(Total)) %>%
ungroup()
情节结果:Plot - Empty Data
用于生成数据子集的代码:
test <- tibble::tribble(
~monthGroup, ~OrderType, ~TransActionCount, ~SalesFulfilled, ~SalesFreight, ~SalesTax, ~ServiceLabor, ~ServiceMaterials, ~Total,
"2017-01", "Credit", 4L, -189, 0, -3.6, 0, 0, -192.6,
"2017-01", "Equipment", 9L, 12286, 0, 250.66, 0, 0, 12536.66,
"2017-01", "Networking", 2L, 9.9, 0, 0, 0, 0, 9.9,
"2017-01", "Part Order", 2L, 658, 0, 39.48, 0, 0, 697.48,
"2017-01", "Service Call", 190L, 0, 0, 0, 9523.62, 2287.9, 12269.38,
"2017-01", "Supply", 76L, 26682.18, 5, 1274.05, 0, 0, 24639.73
)
1 回答
你需要
type = 'column'
和hc_xAxis(categories = test$monthGroup)