简体   繁体   English

在 R 中对齐 Plotly 轴文本

[英]Align Plotly axis text in R

I would like to left align the y-axis text in the following plot:我想左对齐以下 plot 中的 y 轴文本:


fig <- plot_ly(
  y = c("giraffes", " orange orangutans", "pigs"),
  x = c(20, 14, 23),
  name = "SF Zoo",
  type = "bar", 
  orientation = 'h'
)
fig

When the text is uneven in length, I would prefer to have the text aligned to the left.当文本长度不均匀时,我希望文本左对齐。

If possible, I would like a reference provided for what I can pass into the list for yaxis, too.如果可能的话,我也想为我可以传递到 yaxis 列表中的内容提供参考。 Thank you!谢谢!

在此处输入图像描述

from what I found here is no possibility to left align y-axis labels ( https://community.plotly.com/t/left-align-category-labels-on-y-axis/3044 )从我发现这里是不可能左对齐y轴标签( https://community.plotly.com/t/left-align-category-labels-on-y-axis/3044

a work arround would be to put the labels inside the bars or outside of them at the right side:一个解决方法是将标签放在条内或右侧的条外:

library(plotly)

fig %>% 
  plotly::layout(yaxis= list(showticklabels = FALSE)) %>% 
  plotly::style(text = c("giraffes", " orange orangutans", "pigs"), textposition = "auto", insidetextanchor="start")

在此处输入图像描述

You can find the reference for yaxis here: https://plotly.com/r/reference/layout/yaxis/您可以在此处找到 yaxis 的参考: https://plotly.com/r/reference/layout/yaxis/

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

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