[英]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. Plotly是R中最有用的绘图包之一,但我面临着一个非常基本的问题。
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. 由于我的要求是动态的,情节上的条数变化,但我想保持条宽看起来不错。
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.
width选项不会对图形产生任何影响。
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)
ploty中没有名为bar size的选项,但您可以在布局中使用bargap选项。
Yes, you need to set the autosize=F
. 是的,您需要设置
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")))
另一种选择是在
plotlyOutput
设置宽度和高度(保持plotlyOutput
autosize=T
): plotlyOutput("plot", height="700px", width="200px")))
I could not find the answer either, but I found an alternative solution, which is to use dot plot, instead of bar chart. 我也找不到答案,但我找到了另一种解决方案,即使用点图而不是条形图。
See: https://plot.ly/r/dot-plots/ 请参阅: https : //plot.ly/r/dot-plots/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.