Secondary axis in ploty for R and Shiny

烂漫一生 提交于 2021-01-29 12:07:24

问题


EDIT: Regarding my question 2, it seems it is a bug and hasn't been fixed yet as it is not their top priority at the moment. Someone asked to try katex instead of latex, but not sure how that works https://github.com/plotly/plotly.js/issues/559

I have attached an output for a code- https://i.stack.imgur.com/u65if.jpg.

I am trying to plot two y axis and a common x axis using plotly. The issues I am facing are:

  1. I would like the primary and the secondary y axis ticks to share the same gridline. A you can see from the graph, it is not the case. Should I manually change the range? How do I force it to merge with primary y axis gridline?

  2. The hoverlabels don't convert to latex format inspite of using TeX. As you can see from the pic, they stay as \alpha instead of the greek letter

  3. Will renderplotly() work in Shiny with the secondary axis? I am yet to play with it and wanted to know if I should approach it differently.

Here is my code

library(latex2exp)
library(ggplot)
library(plotly)

foo<-data.frame("x"=seq(0,100,1),"y"=rnorm(101),"z"=rnorm(101))

ay <- list(
overlaying = "n",
side = "left"
)

ay2 <- list(
overlaying = "y",
side = "right"

)

fig <- plot_ly()%>% 
add_lines(data=foo,x = ~x, y = ~y,name=TeX("\\alpha") ,line = list(color="blue"))%>%
add_lines(data=foo,x = ~x, y = ~z,name=TeX("\\beta") , yaxis = "y2",line = list(color="red"))%>% 
layout(
yaxis=ay,
yaxis2 = ay2,
hoverlabel = list(font=list(size=20))
)

config(fig,mathjax = 'cdn')


  [1]: https://i.stack.imgur.com/u65if.jpg

来源:https://stackoverflow.com/questions/61052883/secondary-axis-in-ploty-for-r-and-shiny

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!