3

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'))p

This image shows what results when I execute the code.Plot.ly subplot chart

What I would like to have is the same chart, however without the y-axis on the right hand subplot.

askedSep 5, 2016 at 7:26
Dan's user avatar

1 Answer1

1

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))p

enter image description here

answeredSep 7, 2016 at 5:41
Vance Lopez's user avatar
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Sign up orlog in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to ourterms of service and acknowledge you have read ourprivacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.