Search code examples
rr-plotlyviolin-plot

How can I fix the axes in plotly to see the title?


If I am plot a plotly violin plot, it snipps the title away. How can I fix that?

I have followed code:

len <- c(4.5, 3.0, 4.0, 4.0, 3.0, 3.5, 4.5, 3.0, 3.0, 4.0, 
               3.0, 4.5, 4.5, 4.0, 3.0,2.0,2.0,1.0,1.5,1.5,
               3.5, 4.5, 3.5, 5.0, 3.0, 3.0, 4.5, 4.5, 2.5, 4.5)*50
len <- rep(ser,100)

avg <- rep(c(4.5, 3.5, 4.0, 4.0, 4.0, 3.5, 4.5, 4.0, 3.0, 4.0, 
               3.0, 5.0, 4.5, 4.0, 3.0,2.0,2.0,1.0,1.5,1.5,
               3.5, 4.5, 3.5, 3.5, 4.0, 3.0, 4.0, 4.0, 2.5, 4.5),100)

df <- data.frame(len, avg)


df$avg <- round(df$avg)


df %>%
  plot_ly(x = ~avg, y = ~len, split = ~avg,
          type = "violin", box = list(visible = T),
          meanline = list(visible = T), alpha = 0.2
  ) %>%
  layout(title = .(text = "Analytics from John doe"),
         xaxis = .(title = "average"),
         yaxis = .(title = "length",nticks = 20),
         font = .(size = 15))

which gives me: enter image description here


Solution

  • You have to increase the top margin:

      layout(title = list(text = "Analytics from John doe"),
             xaxis = list(title = "average"),
             yaxis = list(title = "length",nticks = 20),
             font = list(size = 15),
             margin = list(l = 70, r = 50, b = 70, t = 100))
    

    enter image description here