简体   繁体   English

plot_ly()中缺少y轴的数字

[英]Numbers of the y-axis missing in plot_ly()

I've done a plot with plot_ly in r : 我在r中用plot_ly完成了一个绘图:

情节

Basically, it's fine. 基本上没关系。 The only problem is that the values of the right y-axis are cut off (it should be 0, 200, 400, 600, 800, 1000). 唯一的问题是右y轴的值被切除(应为0、200、400、600、800、1000)。 Is there a way to adjust the field or something similar? 有没有办法调整场或类似的东西?

plot_ly(scan, x = ~distance, y = ~Available_edges, name ="Available edges") %>%
  add_lines(colors = "blue") %>%
  add_lines(x = ~distance, y = ~cost, colors = "red", name = "cost", yaxis ="y2")  %>%
  add_lines(x = ~distance, y = ~cost_adj, colors = "green", name = "cost_adj", yaxis ="y2")  %>%
  layout(title="Distance scan",
         xaxis=list(autorange = "reversed"),
         xaxis=x, 
         yaxis=y,
         yaxis2 = list(overlaying = "y", 
                       side = "right",
                       yaxis=y2),
         legend = list(x = 0.1, y = 0.5)
         )

You should read Setting Graph Size in R , Plotly has many layout options that may be of interest, specifically automargin . 您应该阅读R中的“设置图形大小” ,Plotly有许多有趣的布局选项,特别是automargin

automargin (boolean) 自动保证金(布尔值)

Determines whether long tick labels automatically grow the figure margins. 确定长刻度标签是否自动增加图形边距。

Example Code 范例程式码

library(plotly)


ay <- list(
  tickfont = list(color = "red"),
  overlaying = "y",
  side = "right",
  automargin = TRUE,
  title = "second y axis"
)

plot_ly()  %>%
  add_lines(
    x = ~ rnorm(10, mean = 50, sd = 25),
    y = ~ rnorm(10, mean = 50000, sd = 25000),
  ) %>%
  add_lines(
    x = ~ rnorm(10, mean = 50, sd = 25),
    y = ~ rnorm(10, mean = 500, sd = 250),
    yaxis = "y2"
  ) %>%
  layout(title = "Double Y Axis - automargin",
         yaxis2 = ay,
         yaxis = list(title = 'first y axis'),
         xaxis = list(title = "x"),
         legend = list(x = 0.1, y = 0.5))

Example Plot 样例图 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM