Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

highcharts - Two y Axis in Highcharter in R

I would like to make a line chart containing one x axis sharing two y axis, one on the left side and the second one on the right of the plot in R.

I found many examples on how to do this but I don't manage to reproduce it in R with the package "highcharter".

Here are the examples :

http://jsfiddle.net/gh/get/jquery/1.7.1/highslide-software/highcharts.com/tree/master/samples/highcharts/yaxis/opposite/

http://www.highcharts.com/demo/combo-dual-axes

Here what I have done so far :

g <- highchart()%>%
hc_xAxis(categories = c("2016-01-01","2016-02-01","2016-03-01","2016-04-01","2016-05-01","2016-06-01","2016-07-01","2016-08-01","2016-09-01","2016-10-01"))%>%
hc_yAxis(
  list(title = list(text = "Yaxis1")),
  list(title = list(text = "Yaxis2"), opposite = TRUE)
)%>%
hc_series(
  list(yAxis = 0, data = c(7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3), name = "Data1"),
  list(yAxis = 1, data = c(8.0, 7.9, 10.5, 15.5, 19.2, 22.5, 28.2, 23.5, 21.3, 14.3), name = "Data2")
)

Does anyone have an idea ?

Thank you !

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In the highcharter official website there is a demo with two axis:

http://jkunst.com/highcharter/highcharts.html#highcharts-home-page-demo

enter image description here

You need to use hc_yAxis_multiples in this case:

highchart() %>% 
  hc_yAxis_multiples(
    list(lineWidth = 3),
    list(showLastLabel = FALSE, opposite = TRUE)
  ) %>% 
  hc_add_series(data = rnorm(10)) %>% 
  hc_add_series(data = rexp(10), type = "spline", yAxis = 1)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...