-1

Is there a way to round decimals in plotly? For example, I am getting the values as 24.32544 M.

Instead of this, can I get as 24.32 M?

asd <- data.frame(a = c(1,2,3,4), b = c(24325443,35345442,3245353453,345353523), c = c(5435352345,234534534,324534534,23453532))
plot_ly(asd, x = ~a, y = ~b, name = 'b', type = 'scatter', mode = 'lines') %>%  
  add_trace(y = ~c, name = 'c', mode = 'lines') %>% 
  layout(xaxis = list(title = paste0("Week"),showgrid = F,rangemode = "tozero"), 
         yaxis = list(title = "",showgrid = F,rangemode = "tozero"),
         legend = legend_cus,
         hovermode = 'x unified')
dash2
  • 2,024
  • 6
  • 15
manu p
  • 952
  • 4
  • 10

1 Answers1

-1
p <- ggplot(asd, aes(a, b,
                     text = paste0("a: ", round(a), "</br></br>b: ", round(b)))) 
       + geom_point()

ggplotly(p, tooltip = "text")

To conver to million format see: Format numbers with million (M) and billion (B) suffixes

VYago
  • 325
  • 2
  • 9