我想通过将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%。
答案 0 :(得分:0)
您需要在min
内添加max
和hc_yAxis
参数:
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