Plot.ly R中的双轴格式化内容

Plot.ly Double- Axis Formatting Content in R

我在使用 Plot.ly 双轴图格式化轴时遇到问题。我试图让 y 轴之一在数字前面包含“$”符号,但我找不到任何代码。希望有人能帮我解决这个问题。

ay <- list(
tickfont = list(color = "red"),
overlaying = "y",
side = "right"
)

p <- plot_ly(data = df, x = days, y = sales, name = "Sales",type="bar") %>%
add_trace(x = days, y = Sales/Day, name = "Sales/Day", yaxis = "y2") %>%
layout(title = "Double Y Axis", yaxis2 = ay)

所以在上面的代码中,我想在两个 y 轴(Sales 和 Sales/day)上添加一个“$”符号。

由于您没有提供可重现的示例,我将使用 plotly 网站上的示例。你可以试试:

library(plotly)
ay <- list(
  tickfont = list(color = "red"),
  overlaying = "y",
  side = "right"
)
plot_ly(x = 1:3, y = 10*(1:3), name = "slope of 10") %>%
  add_trace(x = 2:4, y = 1:3, name = "slope of 1", yaxis = "y2") %>%
  layout(title = "Double Y Axis", yaxis2 = ay, yaxis = list(showtickprefix = "all", tickprefix = "$"))