Search code examples
raxis-labelsr-plotlyggplotly

How to set decimal places at y-axis?


Im working on a Shinyapp, where i want to show some plots. I have one parameter, where at the y-axis R gives me values like 0.180000000008. Is there any posibility to set the limit of decimal places at 2? So it would be 0.18

I thought about using something like

breaks=round(seq(1.5, 1.8, by = 0.1),1)

but depending on the date range in my app, the y axis changes from 0.16-0.18 to 0.15-0.35, so this wont work for me. My code looks like this:

ly_tcc <- plot_ly(PU29_Data_Zwischenstand[grepl("turbidity_feed",
          PU29_Data_Zwischenstand$parameter),],x= ~datetime,y= ~value,
          height=900,type="scatter",mode="lines+markers",
          marker=list(size=2,color="blue"),line=list(color=alpha("blue",0.2))) %>%
          layout(
          xaxis=list(title="Datum",tickformat="%Y-%m-%d"),
          yaxis=list(title="turbidity feed",exponentformat="none", tickformat="."),
          showlegend=F)

Thanks a lot for your help.


Solution

  • Could solve it, changing the code to

     ly_tcc <- plot_ly(PU29_Data_Zwischenstand_median[grepl("turbidity_feed",PU29_Data_Zwischenstand_median$parameter),],x= ~datetime,y= ~value,height=900,type="scatter",mode="lines+markers",
                              marker=list(size=2,color="blue"),line=list(color=alpha("blue",0.2))) %>%
                       layout(xaxis=list(title="Datum",tickformat="%Y-%m-%d"),
                              yaxis=list(title="turbidity feed",labels = fmt_dcimals(3)),
                              showlegend=F)