I'm trying to combine a graph generated with ggplot2 and converted to plot_ly,
p1 <- ggplot(data, aes(x = x, y = y)) +
scale_x_log10(limits = c(0.1, 1e7), breaks = 10^(0:7), expand = c(0, 0)) +
scale_y_log10(limits = c(0.1, 1e7), breaks = 10^(0:7), expand = c(0, 0)) +
geom_abline(aes(intercept =l1, slope = 1), color = "blue") +
geom_abline(aes(intercept = -l1, slope = 1), color = "blue") +
geom_abline(aes(intercept =l2, slope = 1), color = "red") +
geom_abline(aes(intercept = -l2, slope = 1), color = "red") +
geom_abline(aes(intercept =l3, slope = 1), color = "green") +
geom_abline(aes(intercept = -l3, slope = 1), color = "green")
plot <- ggplotly(plot)
with another one generated with plot_ly
.
p2 <- plot_ly(data = df, x = ~sample1, y = ~sample2, type = "scatter",
mode = "markers", marker = list(symbol = "cross",size = 4, opacity = 0.5,
color = "rgba(50,50,50,0.5)",alpha = I(0.8))) %>%
layout(xaxis = list(type = "log", range = c(-1, 7), dtick = 1,
ticklen = 5, showgrid=TRUE, gridwidth=1),
yaxis = list(type = "log", range = c(-1, 7), dtick = 1,
ticklen = 5))
Basically, I want the first plot to be the background of the second one, keeping also the axis as they are in the second plot.