I am attempting to use subplots with theplot.ly R library for interactive online charting. I can successfully create a subplot, however am struggling to only have a single y-axis that is common to both charts.
Theplot.ly website does provide an example for a common x-axis, however this is done slightly differently using and additionaltrace rather than thegroup option that is provided within theplot_ly() function.
example code:
library(data.table)library(plotly)dt <- data.table(x = c("A","B","C","D","A","B","C","D"), y = c(12,4,3,9,5,10,3,7), group = factor(c(rep("G1",4),rep("G2",4))))dt$id <- as.integer(dt$group)xx <- xaxis_standardyy <- yaxis_standardp <- plot_ly(dt, x=x, y=y, group = group, xaxis = paste0("x",id)) p <- layout(p, yaxis = list(range = c(0, max(y))))p <- subplot(p, margin = 0.05) p <- layout(p,showlegend = F, yaxis = list(anchor = 'x1'))pThis image shows what results when I execute the code.
What I would like to have is the same chart, however without the y-axis on the right hand subplot.
1 Answer1
Subplots are on separate axes labeledxaxis2,yaxis2, etc. Those axes are also arguments tolayout().
p <- layout(p, showlegend = F, yaxis = list(anchor = 'x1'), yaxis2 = list(showticklabels = F))pComments
Explore related questions
See similar questions with these tags.
