18

When using the Rplotly package version 4.5.6 I haven't been able to figure out how to get axis labels to appear when combining multiple plots usingsubplot. Here is an example where no x-axis labels appear.

require(plotly)a <- data.frame(x1=1:3,   y=30:32)b <- data.frame(x2=11:13, y=31:33)u <- plot_ly(a)u <- add_lines(u, x=~x1, y=~y)v <- plot_ly(b)v <- add_lines(v, x=~x2, y=~y)subplot(u, v, shareY=TRUE)
MLavoie's user avatar
MLavoie
9,91641 gold badges42 silver badges58 bronze badges
askedDec 25, 2016 at 22:22
Frank Harrell's user avatar
0

1 Answer1

22

To get x-axis labels to show up withsubplot, you can settitleX = TRUE. The default istitleX = shareX, and in your example,shareX = FALSE (the default).

subplot(u, v, shareY = TRUE, titleX = TRUE)

enter image description here

answeredDec 26, 2016 at 0:56
Jota's user avatar
Sign up to request clarification or add additional context in comments.

2 Comments

Sorry I missed that. A somewhat related question is that I really want to use a general character string for the axis labels. I can add calls tolayout(..., xaxis=list(title=...)) for the individual plots before callingsubplot withtitleX=TRUE and it also works. I just wonder if callinglayout is the recommended approach.
@FrankHarrell usinglayout as you describe seems to be the approach in most examples I see. You can also use layout after constructing the subplot. For instance:subplot(u, v, shareY = TRUE, titleX = TRUE) %>% layout(xaxis = list(title = "X1"), xaxis2 = list(title = "X2")).

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.