代码之家  ›  专栏  ›  技术社区  ›  symbolrush

将勾号标签更改为plotly中的特定字符串

  •  4
  • symbolrush  · 技术社区  · 7 年前

    我有 plotly 我想把坐标轴记号标签改成特定字符串的图形。考虑以下示例:

    library(plotly)
    p <- plot_ly(data = iris, x = ~Sepal.Length, y = ~Petal.Length)
    

    enter image description here

    假设我想抑制所有数字xaxis记号标签,而不是只打印字符串“min” x = 4.5 “max”在 x = 8 .

    阴谋地


    旁注 :我知道这对于基R图是可能的,例如。 here ggplot2 通过设置 scale_x_continuous(breaks = c(4.5, 8), labels= c("4.5" = "min", "8" = "max")) .

    是否也有一种方法可以实现这一点 阴谋地 …不幸的是 阴谋地 docs 似乎没有解决办法。。

    1 回复  |  直到 7 年前
        1
  •  8
  •   symbolrush    7 年前

    多亏了@eipi10和@Jon Spring,我才知道:

    library(plotly)
    plot_ly(data = iris, x = ~Sepal.Length, y = ~Petal.Length) %>% 
      layout(xaxis = list(tickvals = c(4.5, 8), ticktext = c("min", "max")))
    

    这正是我在寻找和产生的:

    enter image description here