Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plotly: how to increase width Y axis?

Tags:

plot

r

plotly

I want to increase the width of the Y-axis of a plotly horizontal bar chart. Right now, text falls of the plot because the y axis is too narrow.

You can see the same happening on the examples page of Plotly, where the categories are simple not readable very well.

I can't find a way to increase width. Help is highly appreciated!

Example code:

library(plotly)
p <- plot_ly(x = c(20, 14, 23), 
  y = c('long string which is not readable', 
    'orangutans (not readable)', 
    'monkeys'), 
  type = 'bar', 
  orientation = 'h')
like image 443
Dendrobates Avatar asked Mar 13 '26 10:03

Dendrobates


1 Answers

Plotly hid this quite well... You can change this in the layout of the xaxis, under domain.

The following will work:

ax <- list(
        domain = list(0.2, 1)
      )
p <- plot_ly(x = c(20, 14, 23), 
  y = c('long string which is not readable', 
    'orangutans (not readable)', 
    'monkeys'), 
  type = 'bar', 
  orientation = 'h') %>%
layout(xaxis = ax)

General tip: Plotly has an online editor, where you can export a JSON object, which contains all the settings. Then, searching through that object might help the find the right settings.

like image 62
Dendrobates Avatar answered Mar 15 '26 03:03

Dendrobates



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!