Long x labels in subplot() get cut off from plot
还没有人认领这个 Issue。
- 主要语言
- R
- 星标
- 2.7k
- 派生
- 641
- PR 合并指标
- 30 天内没有已合并 PR
描述
I've created a shiny app that uses plotly::subplot(), and one of the interactive aspects of this app is that the size of the label can vary depending on user selection.
I've noticed that if there is a label that is really long (in my app the "magic number" is 55 characters, in the following reprex it is higher), that label length is ignored for sizing the plots, even with automargin = TRUE.
library(shiny)
library(plotly)
library(dplyr)
library(purrr)
#Creating dataset with 3 different sample groups, each one with 2 levels
group1 <- c("G1", "G2")
group2 <- c("Longer labels make the plot area smaller", "That's nice!")
group3 <- c("Really long labels get cut off the plot, I don't know why, that's weird", "Another label")
groups <- c("Group1", "Group2", "Group3")
df <- as.data.frame(do.call(paste0, replicate(50, sample(LETTERS, 10, TRUE), FALSE)))
df <- df %>%
mutate(Group1 = sample(group1, nrow(.), replace = TRUE),
Group2 = sample(group2, nrow(.), replace = TRUE),
Group3 = sample(group3, nrow(.), replace = TRUE),
value = rnorm(nrow(.), 0,10))
#App
ui <- fluidPage(
titlePanel("Testing large labels"),
sidebarLayout(
sidebarPanel(
checkboxGroupInput("groups", "Select Groups", choices = groups, selected = groups[1])
),
mainPanel(plotlyOutput("plots", height = "700px"))
)
)
server <- function(input, output) {
list_of_plots <- reactive({
purrr::map(input$groups, .f = function(group){
plot_ly(
df,
x = df[[group]],
y = df$value,
type = 'violin',
hoverinfo = 'text',
showlegend = FALSE,
box = list(
visible = TRUE
),
meanline = list(
visible = TRUE
))%>%
layout(
autosize = TRUE,
xaxis = list(automargin = TRUE,
tickangle = 80)
)
})
})
output$plots <- renderPlotly(
plotly::subplot(list_of_plots(), shareX = TRUE, shareY = TRUE)
)
}
shinyApp(ui, server)
In the app, we have the following behavior, based on the selected groups:
- Group1 + Group2: plot size is adjusted to the longer label in Group2. (the expected behavior)
- Group1 + Group2 + Group3: long label in group 3 gets cut off
- Group1 + Group3: only the labels in Group1 are used to define the plot size.
In my app, I was able to change the long label to a shorter version, but I was wondering if there is any workaround around this problem.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先运行提供的 R/Shiny reprex,并检查 plotly::subplot() 以及 xaxis automargin 和 tickangle 设置。当选择 Group1、Group2 和 Group3 时,最长的 x 轴标签仍保持可见(包括 Group1 + Group3 的情况),即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- r
- 领域
- data-visualization
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100