如何在 highchart() 图中设置 yAxis 限制?
How can I set the yAxis limits within highchart() plot?
我想通过将 y 轴的每一侧设置为 100% 来平衡绘图的外观。
我尝试应用 Highcharts 的一些解决方案,但我正在努力将语法转换为 R。
library(highcharter)
categories = c('2015', '2016', '2017', '2018', '2019')
hc <-highchart()%>%
hc_chart(type= 'bar')%>%
hc_title(text= 'My Assessment')%>%
hc_subtitle(text= 'Mathematics')%>%
hc_legend(enabled = TRUE) %>%
hc_xAxis(
list(categories = categories)) %>%
hc_tooltip(
shared = FALSE,
formatter = JS("function () {
return this.point.category + '<br/>' +
Highcharts.numberFormat(Math.abs(this.point.y), 1);}"))%>%
hc_yAxis(title = list(
text= 'Percent of Students in Performance Levels'),
labels = list(
formatter = JS("function () {
return Math.abs(this.value) + '%';
}")))%>%
hc_plotOptions(series = list(stacking= 'normal'))%>%
hc_series(
list(name = 'Not Yet Met',
data = c(-3, -4, -5, -6,-4),
legendIndex = 1),
list(name = 'Partially Met',
data = c(-12, -13, -14, -15, -20),
legendIndex = 2),
list(name = 'Approached',
data= c(-10, -11, -12, -13, -15),
legendIndex = 3),
list(name= 'Exceeds',
data= c(11, 10, 10, 11, 20),
legendIndex = 5),
list(name= 'Meets',
data= c(64, 62, 60, 55, 41),
legendIndex = 4)
)
hc
我希望看到在 y 轴的正侧和负侧以 100% 的比例重新生成绘图。该图自动生成 40% 作为负端的限制,80% 作为正端的限制。
您需要在 hc_yAxis
:
中添加 min
和 max
参数
library(highcharter)
categories = c('2015', '2016', '2017', '2018', '2019')
hc <-highchart()%>%
hc_chart(type= 'bar')%>%
hc_title(text= 'My Assessment')%>%
hc_subtitle(text= 'Mathematics')%>%
hc_legend(enabled = TRUE) %>%
hc_xAxis(
list(categories = categories)) %>%
hc_tooltip(
shared = FALSE,
formatter = JS("function () {
return this.point.category + '<br/>' +
Highcharts.numberFormat(Math.abs(this.point.y), 1);}"))%>%
hc_yAxis(title = list(
text= 'Percent of Students in Performance Levels'),
labels = list(
formatter = JS("function () {
return Math.abs(this.value) + '%';
}")),
##### here add min and max
min=-100,max=100
)%>%
hc_plotOptions(series = list(stacking= 'normal'))%>%
hc_series(
list(name = 'Not Yet Met',
data = c(-3, -4, -5, -6,-4),
legendIndex = 1),
list(name = 'Partially Met',
data = c(-12, -13, -14, -15, -20),
legendIndex = 2),
list(name = 'Approached',
data= c(-10, -11, -12, -13, -15),
legendIndex = 3),
list(name= 'Exceeds',
data= c(11, 10, 10, 11, 20),
legendIndex = 5),
list(name= 'Meets',
data= c(64, 62, 60, 55, 41),
legendIndex = 4)
)
hc
我想通过将 y 轴的每一侧设置为 100% 来平衡绘图的外观。 我尝试应用 Highcharts 的一些解决方案,但我正在努力将语法转换为 R。
library(highcharter)
categories = c('2015', '2016', '2017', '2018', '2019')
hc <-highchart()%>%
hc_chart(type= 'bar')%>%
hc_title(text= 'My Assessment')%>%
hc_subtitle(text= 'Mathematics')%>%
hc_legend(enabled = TRUE) %>%
hc_xAxis(
list(categories = categories)) %>%
hc_tooltip(
shared = FALSE,
formatter = JS("function () {
return this.point.category + '<br/>' +
Highcharts.numberFormat(Math.abs(this.point.y), 1);}"))%>%
hc_yAxis(title = list(
text= 'Percent of Students in Performance Levels'),
labels = list(
formatter = JS("function () {
return Math.abs(this.value) + '%';
}")))%>%
hc_plotOptions(series = list(stacking= 'normal'))%>%
hc_series(
list(name = 'Not Yet Met',
data = c(-3, -4, -5, -6,-4),
legendIndex = 1),
list(name = 'Partially Met',
data = c(-12, -13, -14, -15, -20),
legendIndex = 2),
list(name = 'Approached',
data= c(-10, -11, -12, -13, -15),
legendIndex = 3),
list(name= 'Exceeds',
data= c(11, 10, 10, 11, 20),
legendIndex = 5),
list(name= 'Meets',
data= c(64, 62, 60, 55, 41),
legendIndex = 4)
)
hc
我希望看到在 y 轴的正侧和负侧以 100% 的比例重新生成绘图。该图自动生成 40% 作为负端的限制,80% 作为正端的限制。
您需要在 hc_yAxis
:
min
和 max
参数
library(highcharter)
categories = c('2015', '2016', '2017', '2018', '2019')
hc <-highchart()%>%
hc_chart(type= 'bar')%>%
hc_title(text= 'My Assessment')%>%
hc_subtitle(text= 'Mathematics')%>%
hc_legend(enabled = TRUE) %>%
hc_xAxis(
list(categories = categories)) %>%
hc_tooltip(
shared = FALSE,
formatter = JS("function () {
return this.point.category + '<br/>' +
Highcharts.numberFormat(Math.abs(this.point.y), 1);}"))%>%
hc_yAxis(title = list(
text= 'Percent of Students in Performance Levels'),
labels = list(
formatter = JS("function () {
return Math.abs(this.value) + '%';
}")),
##### here add min and max
min=-100,max=100
)%>%
hc_plotOptions(series = list(stacking= 'normal'))%>%
hc_series(
list(name = 'Not Yet Met',
data = c(-3, -4, -5, -6,-4),
legendIndex = 1),
list(name = 'Partially Met',
data = c(-12, -13, -14, -15, -20),
legendIndex = 2),
list(name = 'Approached',
data= c(-10, -11, -12, -13, -15),
legendIndex = 3),
list(name= 'Exceeds',
data= c(11, 10, 10, 11, 20),
legendIndex = 5),
list(name= 'Meets',
data= c(64, 62, 60, 55, 41),
legendIndex = 4)
)
hc