-
Notifications
You must be signed in to change notification settings - Fork 633
Enchance subplot()
's ability to handle pre-specified domain(s)
#376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The shared axes issue is reported in #298. The As for controlling the widths/heights of subplots -- for now you'll have to x <- rnorm(100)
y <- rnorm(100)
p1 <- plot_ly(x = x, type = "histogram")
p2 <- plotly_empty()
p3 <- plot_ly(x = x, y = y, mode = "markers")
p4 <- plot_ly(y = y, type = "histogram")
s <- subplot(p1, p2, p3, p4, nrows = 2)
l <- plotly_build(s)
# alter heights/widths
l$layout$xaxis$domain <- c(0, 0.8)
l$layout$xaxis2$domain <- c(0.8, 1)
l$layout$xaxis3$domain <- c(0, 0.8)
l$layout$xaxis4$domain <- c(0.8, 1)
l$layout$yaxis$domain <- c(0.8, 1)
l$layout$yaxis2$domain <- c(0.8, 1)
l$layout$yaxis3$domain <- c(0, 0.8)
l$layout$yaxis4$domain <- c(0, 0.8)
# axis titles/ticks should go too
l$layout$xaxis$title <- NULL
l$layout$xaxis$showticklabels <- F
l$layout$yaxis4$title <- NULL
l$layout$yaxis4$showticklabels <- F It'd be nice if |
subplot
to share the same axis, respond together to zoom, and control each plots' widthsubplot()
's ability to handle pre-specified domain(s)
Thanks @cpsievert - looking forward to updates on this. With regards, |
Hi @cpsievert - I see here another way of creating this plot: Thanks. |
@talgalili - Here's something you could try. It (sort of) emulates your Hopefully this helps while @cpsievert is working on a more practical solution. x <- rnorm(1000)
y <- rchisq(1000, df = 5)
ds <- data.frame(x,y)
ds %>%
plot_ly(x = x, y = y, type = "scatter", mode = "markers", showlegend = F, opacity = 0.7,
marker = list(symbol = "circle-dot",
size = 8)) %>% # First trace
add_trace(y = y, type = "histogram", xaxis = "x2", orientation = "h") %>% # Second trace; Note the use of "x2"
add_trace(x = x, type = "histogram", yaxis = "y2") %>% # Second trace; Note the use of "x2"
layout(title = "Marginal Histograms using Multiple Axis",
xaxis = list(title = "X variable",
domain = c(0,0.85),
range = c(-3,3),
showgrid = TRUE),
xaxis2 = list(title = "Y Histogram",
domain = c(0.85,1),
zeroline = FALSE),
yaxis = list(title = "Y variable",
range = c(0,30),
domain = c(0,0.85),
showgrid = TRUE),
yaxis2 = list(title = "X Histogram",
domain = c(0.85,1),
zeroline = FALSE)) |
Hi @royr2 - thank you for the code tip. I have a followup question:
Could you please show a similar example as you did, but using the output of the objects in my original question? (i.e.: hist_top, empty, scatter, hist_right) Thanks! Tal |
Code for reproducing the error:
Output is:
|
o.k., looking at this more, I see that my previous code wouldn't make sense. I see that add_trace takes a plotly object and adds another element to it (but it doesn't seem to allow the merging of two plotly objects). If not then I guess the only way to get what I asked is (as the ticket says): "Enchance This would be VERY useful for my work, so I hope this could get addressed. Thanks, |
There isn't any reason why |
Fixed via dd9a3fa |
subplot seems the way to create a scatterplot with marginal histograms in plotly.
However, in order to have it work it needs to:
Example of how it should look like:
Which looks like this:
And this is how it actually looks like (which should be corrected):
The text was updated successfully, but these errors were encountered: