4

when I use ggplotly in jupyterlab the output gets truncated. How can I force jupyter to display it properly ? For some reason if I just use ggplot the graph can be as large as it needs to be

    set.seed(1L)                                                                                                                             
    values <- rnorm(n = 366L)                                                                                                                
    plot_data <- data.frame(date = seq(as.Date("2011-01-01"), as.Date("2012-01-01"), 1),                                                     
                            value = values,                                                                                                  
                            sign = ifelse(values > 0, "positive", "negative"), size = ifelse(abs(values) > 2, "big", "small")                
                            )                                                                                                                
    p <- ggplot(data = plot_data) + aes(x = date, y = value, color = sign) + geom_line()                                                     
                                                                                                                                             
    vertical <- as.Date(c("2011-02-01", "2011-10-01"))                                                                                       
    names(vertical) <- c("test", "test2")                                                                                                    
    p <- p + geom_vline(xintercept = vertical, linetype = "dashed", color = "orange")                                                        
                                                                                                                                             
    data_geom <- data.frame(v_x = vertical, v_label = names(vertical), v_y = rep(2.5, 2))                                                    
    p <- p + geom_text(data = data_geom, aes_string(x = "v_x", label = "v_label", y = "v_y"), colour = "orange", angle = 90, check_overlap = TRUE)
    ggplotly(p)

This gives me

enter image description here

statquant
  • 13,672
  • 21
  • 91
  • 162
  • In the screen copy above, the last command is ggplotly(p) : this is confusing, is it a `ggplot`(as you mentionned) or a `ggplotly` plot? Also not fully clear to me what gets truncated. – Waldi Sep 13 '20 at 08:35
  • 2
    Large visualizations gets truncated in jupyter notebooks by default. You can expand the result by double clicking on the block to the left. I believe the same is true to jupyter-lab. – Oliver Sep 13 '20 at 10:32
  • no that does not work – statquant Sep 17 '20 at 17:28
  • https://github.com/plotly/dashR/issues/156 – Nbody Sep 19 '20 at 05:55
  • The ggplotly documentation says that: 'Conversion of relative sizes depends on the size of the current graphics device (if no device is open, width/height of a new (off-screen) device defaults to 640/480). In other words, height and width must be specified at runtime to ensure sizing is correct.' – Onur Baştürk Sep 19 '20 at 21:33

0 Answers0