[英]Setting Order of R Highcharter Categories
I noticed that my bar graphs change in order based on alphabetical order.我注意到我的条形图按字母顺序变化。 I'm using a selectinput, thus if a person who is selected with a name beginning in A, they are at the top, but if it is a letter after C, then they move to the bottom.我正在使用 selectinput,因此如果选择的人的名字以 A 开头,则他们位于顶部,但如果它是 C 之后的字母,则他们移至底部。 This is not based on the value of the bars, but seems tied to the names.这不是基于条的值,而是似乎与名称有关。 How can I keep the ProviderName at top always?如何始终将 ProviderName 保持在顶部?
My hc code is below我的hc代码如下
hchart(
comparison_prov_df,
type = "bar",
hcaes(x = Metric, y = Value, group = ProviderName),
colorByPoint = F,
showInLegend = T,
dataLabels = list(enabled = T)
) %>%
hc_chart(zoomType = "xy") %>%
hc_tooltip(crosshairs = TRUE, shared = FALSE, borderWidth = 1) %>%
hc_credits(
enabled = TRUE,
text = ""
) %>%
hc_add_theme(hc_theme_elementary()) %>%
hc_legend(enabled = TRUE) %>%
hc_exporting(
enabled = TRUE,
filename = "data"
) %>%
hc_title(
text = "Title",
align = "left"
) %>%
hc_yAxis(
title = list(text = "Y Axis"),
labels = list(
reserveSpace = TRUE,
overflow = "justify"
)
) %>%
hc_xAxis(title = "") %>%
hc_tooltip(pointFormat = "{point.y:.1f}")
I am not sure what the original data is like, but I'll provide a simple example of one way to change the order of items on an axis.我不确定原始数据是什么样的,但我将提供一个简单示例,说明一种更改轴上项目顺序的方法。 You can change the order by simply using hc_xAxis
and then listing the category order.您可以通过简单地使用hc_xAxis
然后列出类别顺序来更改顺序。
library(highcharter)
library(tidyverse)
df %>%
hchart("bar", hcaes(x = category, y = value, group = group)) %>%
hc_xAxis(
categories = list(
"Pineapples",
"Strawberries",
"Apples",
"Plums",
"Blueberries",
"Oranges"
)
)
Output Output
Data数据
set.seed(326)
df <-
data.frame(category = rep(c(
"Apples", "Oranges", "Plums", "Pineapples", "Strawberries", "Blueberries"
), each = 2),
value = round(runif(12, min = 0, max = 100)),
group = rep(c(2020, 2021), 6))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.