Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix width of bar in plotly R

Plotly is one of the most useful plotting packages in R, but I am facing a very basic issue with it.

When I am drawing a barplot , it looks ok in a small screen, but as soon as I resize the window , it covers the whole window, making it ugly.

As my requirement is dynamic , number of bars on the plot changes, but I want to keep the bar width look decent.

enter image description here

But when it gets resized

the code which I am using to plot the barplot is simple and I hope need not be explained . The width option doesnt make any impact on the graph.

Am I missing anything?

 ds <- as.data.frame(matrix(c('some_name',2300),nrow = 1,ncol=2))
colnames(ds) <- c('name','value')

plot_ly(ds,x=name,y=value,type='bar') %>% layout(width = 0.1)
like image 349
Mukesh Kumar Singh Avatar asked May 20 '16 11:05

Mukesh Kumar Singh


2 Answers

There is no such option called bar size in ploty, but you can use bargap option in the layout.

like image 108
Chaitanya Nekkalapudi Avatar answered Oct 27 '22 21:10

Chaitanya Nekkalapudi


Yes, you need to set the autosize=F. So correctly it should be :

plot_ly(ds,x=name,y=value,type='bar') %>% layout(width = 100, autosize=F)

Another option is to set width and height in the plotlyOutput (keeping the autosize=T): plotlyOutput("plot", height="700px", width="200px")))

like image 25
amberv Avatar answered Oct 27 '22 20:10

amberv