如何允许Plotly bar文本溢出bar?

如何允许Plotly bar文本溢出bar?,r,layout,plotly,bar-chart,r-plotly,R,Layout,Plotly,Bar Chart,R Plotly,如何获取dr5的文本大小,以及较短条的dr3的文本大小?如果文本长度超过条跨度,我希望文本溢出到条的末端 我尝试在版面中使用uniformtext,但这将所有文本压缩为使用的最小字体。如何将所有字体更改为使用的最大字体 library(plotly) #测试长文本和短条 xValues这可以通过如下方式通过添加标签来实现: 顺便说一句:我把向量放在df中。对我来说似乎更自然 library(plotly) # Test long text and short bars xValues <

如何获取dr5的文本大小,以及较短条的dr3的文本大小?如果文本长度超过条跨度,我希望文本溢出到条的末端

我尝试在版面中使用uniformtext,但这将所有文本压缩为使用的最小字体。如何将所有字体更改为使用的最大字体

library(plotly)
#测试长文本和短条

xValues这可以通过如下方式通过添加标签来实现:

顺便说一句:我把向量放在df中。对我来说似乎更自然

library(plotly)

# Test long text and short bars
xValues <- c("loooooooooooooooooonnnnnngg","lonnnnnnnnnnggggggg",
             "dr3","dr4","dr5")
yValues <- c(0.5,1,2,0.22,10)

df <- data.frame(
  x = xValues,
  y = yValues
)

bar <- plot_ly(df, x = ~y, y = ~x, text = ~x) %>% 
  add_trace(
    type = 'bar',
    orientation = 'h',
    showlegend = F) %>% 
  add_text(x = 0.1, textposition = "middleright") %>% 
  layout(yaxis = list(zeroline = FALSE,showline = FALSE, showticklabels = FALSE))

bar
library(plotly)
#测试长文本和短条

xValues这可以通过如下方式通过添加标签来实现:

顺便说一句:我把向量放在df中。对我来说似乎更自然

library(plotly)

# Test long text and short bars
xValues <- c("loooooooooooooooooonnnnnngg","lonnnnnnnnnnggggggg",
             "dr3","dr4","dr5")
yValues <- c(0.5,1,2,0.22,10)

df <- data.frame(
  x = xValues,
  y = yValues
)

bar <- plot_ly(df, x = ~y, y = ~x, text = ~x) %>% 
  add_trace(
    type = 'bar',
    orientation = 'h',
    showlegend = F) %>% 
  add_text(x = 0.1, textposition = "middleright") %>% 
  layout(yaxis = list(zeroline = FALSE,showline = FALSE, showticklabels = FALSE))

bar
library(plotly)
#测试长文本和短条

理想情况下,我希望避免硬编码任何坐标。文本前面还有一个空格,我想删除。对不起。通过设置
x=0
,可以删除标签前的空格。我也不喜欢硬编码。但是,在这种情况下,我认为可以将x设置为0,因为条形图自然开始(或应该开始(;)在零。理想情况下,我希望避免硬编码任何坐标。文本前面还有一个空格,我想删除。对不起。您可以通过设置
x=0
来删除标签前面的空格。我也不喜欢硬编码。但是,在这种情况下,我认为可以在条形图自然开始时将x设置为0(或应该从零开始(;)。