悬停标签可以正确显示标签,但是我无法在栏下获得正确的类别标签。
这是工作示例:
library(highcharter)
A <- data.frame(x=c(1,2,3,1,2,3),
y=c(0.7,0.8,0.7,0.3,0.2,0.3),
group=factor(c("A","A","A","B","B","B")),
cluster=c("C1","C1","C2","C1","C1","C2"),
name=c("John","Sally","Ed","John","Sally","Ed"),
stringsAsFactors=F)
A %>%
hchart(.,"column",hcaes(x="x",y="y",group="group")) %>%
hc_xAxis(title=list(text=NULL),allowDecimals=FALSE,categories=A$name[1:3]) %>%
hc_plotOptions(column=list(animation=FALSE,stacking="normal"))
我尝试设置categories=A$name
以防它需要六个值,但这是行不通的。我曾尝试更改某些x轴选项(startonTick
,minPadding
,min
,max
),但似乎无法使其正常工作。
我在x轴上使用变量'x'而不是变量'names'来保持特定顺序,否则它将按字母顺序排序。
答案 0 :(得分:0)
问题与x轴为数字有关。两种获取您想要的方法。
首先,我将x
分配给name
A %>%
hchart(.,"column",hcaes(x="name",y="y",group="group")) %>%
hc_plotOptions(column=list(animation=FALSE,stacking="normal"))
其他方法是声明A$x
一个因素
A %>%
dplyr::mutate(x = as.factor(x)) %>%
hchart(.,"column",hcaes(x="x",y="y",group="group")) %>%
hc_xAxis(title=list(text=NULL),allowDecimals=FALSE,categories=A$name[1:3]) %>%
hc_plotOptions(column=list(animation=FALSE,stacking="normal"))