更改绘图框的宽度和/或它们之间的空间
我已经对数据进行了分组,我想使用r
的 plotly 软件包将其绘制为一组框图,并控制框的宽度和/或主题之间的空间。
以下是数据:
set.seed(1)
df <- data.frame(type = c(rep("t1", 1000), rep("t2", 1000), rep("t3", 1000), rep("t4", 1000), rep("t5", 1000), rep("t6", 1000)),
age = rep(c(rep("y", 500),rep("o", 500)), 6),
value = rep(c(runif(500, 5, 10), runif(500, 7.5, 12.5)), 6),
stringsAsFactors = F)
df$age <- factor(df$age, levels = c("y", "o"), ordered = T)
以下plotly
's tutorial 这是我如何绘制它:
library(plotly)
library(dplyr)
plot_ly(x = df$type, y = df$value, name = df$age, color = df$type, type = 'box',showlegend = F) %>%
layout(yaxis=list(title="Diversity"),boxmode='group')
盒子出来太窄的地方以及相同类型
的框之间的空间以及不同的类型
s之间的空间大的。
知道如何更改框宽度和/或空间吗?
I have grouped data which I want to plot as a group of box plots using R
's plotly
package, and control the width of the boxes and/or the space between theme.
Here are the data:
set.seed(1)
df <- data.frame(type = c(rep("t1", 1000), rep("t2", 1000), rep("t3", 1000), rep("t4", 1000), rep("t5", 1000), rep("t6", 1000)),
age = rep(c(rep("y", 500),rep("o", 500)), 6),
value = rep(c(runif(500, 5, 10), runif(500, 7.5, 12.5)), 6),
stringsAsFactors = F)
df$age <- factor(df$age, levels = c("y", "o"), ordered = T)
Following plotly
's tutorial this is how I'm plotting it:
library(plotly)
library(dplyr)
plot_ly(x = df$type, y = df$value, name = df$age, color = df$type, type = 'box',showlegend = F) %>%
layout(yaxis=list(title="Diversity"),boxmode='group')
Where the boxes come out too narrow and the space both between boxes of the same type
as well as the space between the different type
s are big.
Any idea how to change the box widths and/or the spaces?
According to this post, in python
the boxgap
and boxgroupgap
control these aspects.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
类似于Python版本,布局参数为被记录为在这里可以作为参数更改为功能
布局
:Analogous to the python version, layout parameters as being documented here can be changed as arguments of the function
layout
:一种选择是使用连续的X轴。在这里使用ggplotly:
plot
One alternative is to use a continuous x-axis. Here with ggplotly instead:
plot