Long x labels in subplot() get cut off from plot
まだ誰も着手していません。
- 主要言語
- 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 にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、提供された R/Shiny の reprex を実行し、xaxis の automargin および tickangle 設定と併せて plotly::subplot() を調べます。Group1、Group2、Group3 を選択したときに最も長い x 軸ラベルが表示されたままになれば完了です。Group1 + Group3 のケースも含みます。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- r
- 領域
- data-visualization
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 45/100