为什么这个 highcharter plot 上没有预期的标签 - R
Why there are no intended labels on this highcharter plot - R
我有以下数据框:
library(dplyr)
library(highcharter)
hc <- structure(list(date_ref = c("2020-03-02", "2021-02-02", "2021-03-02"
), bracket_pay = c("T1", "T1", "T1"), col1 = c(10010, 12010, 11090), col2 = c(9850,
11300, 10080), ratio = c(98.40, 94.09, 90.89)), row.names = c(NA, -3L), class = c("tbl_df", "tbl",
"data.frame"))
数据为:
# A tibble: 3 x 5
date_ref bracket_pay col1 col2 ratio
<chr> <chr> <dbl> <dbl> <dbl>
1 2020-03-02 T1 10010. 9850. 98.4
2 2021-02-02 T1 12010. 11300. 94.1
3 2021-03-02 T1 11090. 10080. 90.9
我想使用 highcharter 创建一个组合图(柱和线)。这是我试过的:
highchart() %>%
hc_yAxis_multiples(
list(title = list(text = "Amount"),
opposite = FALSE),
list(title = list(text = "Percentage"),
opposite = TRUE)) %>%
hc_add_series(hc, hcaes(x = date_ref, y = col2),
yAxis = 0,
name = "Amount",
type = "column",
color = "mediumseagreen") %>%
hc_add_series(hc, hcaes(x = date_ref, y = ratio),
yAxis = 1,
name = "Advanced",
type = "line",
color = "tomato")
情节几乎不错,但是当您看到 X 轴上的标签时,您看到的是 1,2,3
而不是 2020-03-02,2021-02-02,2021-03-03
。顺便说一句 date_ref 是一个字符向量。拜托,我们将不胜感激。
添加 hc_xAxis(type = 'category')
似乎可以解决问题。
highchart() %>%
hc_xAxis(type = 'category') %>%
hc_yAxis_multiples(
list(title = list(text = "Amount"),
opposite = FALSE),
list(title = list(text = "Percentage"),
opposite = TRUE)) %>%
hc_add_series(hc, hcaes(x = date_ref, y = col2),
yAxis = 0,
name = "Amount",
type = "column",
color = "mediumseagreen") %>%
hc_add_series(hc, hcaes(x = date_ref, y = ratio),
yAxis = 1,
name = "Advanced",
type = "line",
color = "tomato")
我有以下数据框:
library(dplyr)
library(highcharter)
hc <- structure(list(date_ref = c("2020-03-02", "2021-02-02", "2021-03-02"
), bracket_pay = c("T1", "T1", "T1"), col1 = c(10010, 12010, 11090), col2 = c(9850,
11300, 10080), ratio = c(98.40, 94.09, 90.89)), row.names = c(NA, -3L), class = c("tbl_df", "tbl",
"data.frame"))
数据为:
# A tibble: 3 x 5
date_ref bracket_pay col1 col2 ratio
<chr> <chr> <dbl> <dbl> <dbl>
1 2020-03-02 T1 10010. 9850. 98.4
2 2021-02-02 T1 12010. 11300. 94.1
3 2021-03-02 T1 11090. 10080. 90.9
我想使用 highcharter 创建一个组合图(柱和线)。这是我试过的:
highchart() %>%
hc_yAxis_multiples(
list(title = list(text = "Amount"),
opposite = FALSE),
list(title = list(text = "Percentage"),
opposite = TRUE)) %>%
hc_add_series(hc, hcaes(x = date_ref, y = col2),
yAxis = 0,
name = "Amount",
type = "column",
color = "mediumseagreen") %>%
hc_add_series(hc, hcaes(x = date_ref, y = ratio),
yAxis = 1,
name = "Advanced",
type = "line",
color = "tomato")
情节几乎不错,但是当您看到 X 轴上的标签时,您看到的是 1,2,3
而不是 2020-03-02,2021-02-02,2021-03-03
。顺便说一句 date_ref 是一个字符向量。拜托,我们将不胜感激。
添加 hc_xAxis(type = 'category')
似乎可以解决问题。
highchart() %>%
hc_xAxis(type = 'category') %>%
hc_yAxis_multiples(
list(title = list(text = "Amount"),
opposite = FALSE),
list(title = list(text = "Percentage"),
opposite = TRUE)) %>%
hc_add_series(hc, hcaes(x = date_ref, y = col2),
yAxis = 0,
name = "Amount",
type = "column",
color = "mediumseagreen") %>%
hc_add_series(hc, hcaes(x = date_ref, y = ratio),
yAxis = 1,
name = "Advanced",
type = "line",
color = "tomato")