Highcharter-R:x 轴值未显示,y 轴上的文本错误
Highcharter-R: x-axis values not showing up, wrong text on y-axis
我正在尝试使用 highcharter R 创建一个混合图表,请参阅下面的完整代码。我无法摆脱以下问题:
- 如何删除两个 y 轴上的文本“值”?我只想显示我的文字(“xxx”和“yyy”)。
- 为什么 x 轴值不显示(2019、2020a、2020b),而是出现在“1”、“2”和“3”列下方?我该如何更改它?
任何帮助将不胜感激,谢谢!
df2 <- data.frame(supp=rep(c("Media", "Mediana"), each=3),
Anno=rep(c("2019", "2020a", "2020b"),2),
Reddito=c(40100, 39000, 38000, 34000, 33000, 32000))
df3<-data.frame(supp=rep(c("Numero indice media", "Numero indice mediana"), each=3),
Anno=rep(c("2019", "2020a", "2020b"),2),
Reddito=c(100, 97, 96, 100, 96, 95))
highchart() %>%
hc_yAxis_multiples(
list(title = list(text = "xxx"),opposite=F),
list(title = list(text = "yyy"),opposite=TRUE),
list(lineWidth = 0),
list(showLastLabel = F, opposite = T))%>%
hc_add_series(data = df2,type="column" ,hcaes(x = "Anno", y = 'Reddito', group = 'supp')) %>%
hc_add_series(data = df3, type = "spline", hcaes(x = 'Anno', y = 'Reddito', group = 'supp'),yAxis = 1)
要回答你的第一个问题,试试这个:
library(highcharter)
highchart() %>%
hc_yAxis_multiples(
list(title=list(text="xxx",margin = 20),
lineWidth = 3,showLastLabel = FALSE,opposite = FALSE),
list(
title=list(text="yyy", margin = 20),
lineWidth = 3,showLastLabel = FALSE, opposite = T)
) %>%
hc_add_series(data = df2,type="column" ,hcaes(x = "Anno", y = 'Reddito', group = 'supp')) %>%
hc_add_series(data = df3, type = "spline", hcaes(x = 'Anno', y = 'Reddito', group = 'supp'),yAxis = 1)
xAxis 的值未按您期望的方式显示,因为您没有定义 xAxis 类型,因此它们默认显示为索引号。如果您在 hc_xAxis
到 category
之间指定类型,它应该可以正常工作。这是最终代码:
library(highcharter)
highchart() %>%
hc_yAxis_multiples(
list(title=list(text="xxx",margin = 20),
lineWidth = 3,showLastLabel = FALSE,opposite = FALSE),
list(
title=list(text="yyy", margin = 20),
lineWidth = 3,showLastLabel = FALSE, opposite = T)
) %>%
# Specify Type
hc_xAxis(type = "category") %>%
hc_add_series(data = df2,type="column" ,hcaes(x = "Anno", y = 'Reddito', group = 'supp')) %>%
hc_add_series(data = df3, type = "spline", hcaes(x = 'Anno', y = 'Reddito', group = 'supp'),yAxis = 1)
我正在尝试使用 highcharter R 创建一个混合图表,请参阅下面的完整代码。我无法摆脱以下问题:
- 如何删除两个 y 轴上的文本“值”?我只想显示我的文字(“xxx”和“yyy”)。
- 为什么 x 轴值不显示(2019、2020a、2020b),而是出现在“1”、“2”和“3”列下方?我该如何更改它?
任何帮助将不胜感激,谢谢!
df2 <- data.frame(supp=rep(c("Media", "Mediana"), each=3),
Anno=rep(c("2019", "2020a", "2020b"),2),
Reddito=c(40100, 39000, 38000, 34000, 33000, 32000))
df3<-data.frame(supp=rep(c("Numero indice media", "Numero indice mediana"), each=3),
Anno=rep(c("2019", "2020a", "2020b"),2),
Reddito=c(100, 97, 96, 100, 96, 95))
highchart() %>%
hc_yAxis_multiples(
list(title = list(text = "xxx"),opposite=F),
list(title = list(text = "yyy"),opposite=TRUE),
list(lineWidth = 0),
list(showLastLabel = F, opposite = T))%>%
hc_add_series(data = df2,type="column" ,hcaes(x = "Anno", y = 'Reddito', group = 'supp')) %>%
hc_add_series(data = df3, type = "spline", hcaes(x = 'Anno', y = 'Reddito', group = 'supp'),yAxis = 1)
要回答你的第一个问题,试试这个:
library(highcharter)
highchart() %>%
hc_yAxis_multiples(
list(title=list(text="xxx",margin = 20),
lineWidth = 3,showLastLabel = FALSE,opposite = FALSE),
list(
title=list(text="yyy", margin = 20),
lineWidth = 3,showLastLabel = FALSE, opposite = T)
) %>%
hc_add_series(data = df2,type="column" ,hcaes(x = "Anno", y = 'Reddito', group = 'supp')) %>%
hc_add_series(data = df3, type = "spline", hcaes(x = 'Anno', y = 'Reddito', group = 'supp'),yAxis = 1)
xAxis 的值未按您期望的方式显示,因为您没有定义 xAxis 类型,因此它们默认显示为索引号。如果您在 hc_xAxis
到 category
之间指定类型,它应该可以正常工作。这是最终代码:
library(highcharter)
highchart() %>%
hc_yAxis_multiples(
list(title=list(text="xxx",margin = 20),
lineWidth = 3,showLastLabel = FALSE,opposite = FALSE),
list(
title=list(text="yyy", margin = 20),
lineWidth = 3,showLastLabel = FALSE, opposite = T)
) %>%
# Specify Type
hc_xAxis(type = "category") %>%
hc_add_series(data = df2,type="column" ,hcaes(x = "Anno", y = 'Reddito', group = 'supp')) %>%
hc_add_series(data = df3, type = "spline", hcaes(x = 'Anno', y = 'Reddito', group = 'supp'),yAxis = 1)