plotly / plotly/plotly.R

Long x labels in subplot() get cut off from plot

Đang mở
#1,760 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

plotly.js
Ngôn ngữ chính
R
Star
2.7k
Fork
641
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu bằng cách chạy reprex R/Shiny được cung cấp và kiểm tra plotly::subplot() cùng với các thiết lập xaxis automargin và tickangle. Công việc được xem là hoàn tất khi các nhãn dài nhất trên trục x vẫn hiển thị khi Group1, Group2 và Group3 được chọn, bao gồm cả trường hợp Group1 + Group3.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
r
Lĩnh vực
data-visualization
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
45/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.