I'm building a r / plotly chart with multicategory x-axis. I found a way to define two x-axis categories with rbind(), but can't seem to find a way to rotate x-axis tick labels for both categories (tickangle property only affects first category, but not the second one).
Tried to google answer (of course) but couldn't find much help.
I found this discussion - they're mentioning label rotation with multicategory plot as one issue to be solved, but there's no conclusion how this is achieved in reality. https://github.com/plotly/plotly.js/issues/2799
library(plotly)
df <- data.frame(
name1 = c('Winter', 'Summer', 'Autumn', 'Winter', 'Winter', 'Summer',
'Winter', 'Autumn'),
name2 = c('VeryVeryVeryLongName_A',
'VeryVeryVeryLongName_A',
'VeryVeryVeryLongName_A',
'VeryVeryVeryLongName_B',
'VeryVeryVeryLongName_B',
'VeryVeryVeryLongName_B',
'VeryVeryVeryLongName_C',
'VeryVeryVeryLongName_C'),
Value = c('10', '11', '9', '8', '7', '6', '9', '10')
)
plot_ly(df) %>%
add_trace(x = rbind(c(~name2, ~name1)), y = ~Value, type = 'scatter', mode = 'markers') %>%
layout(xaxis = list(tickangle = 90)) #this only affects the 1st category (name1), but not the 2nd (name2).
I would like to find a way to define tickangle property for both categories independently (name1 and name2), or alternatively find a way to prevent overlapping 2nd category labels (long names).
Any help is greatly appreciated. Thanks =)