0

How can I plot both the graphs in same window ?

library(shiny)

library(plotly)

shinyServer(function(input, output) {
today <- Sys.Date()
tm1 <- c(2,3,5,7,9)
tm2 <- c(3,4,6,8,9)
x1 <- today + tm1
x2 <- today + tm2
y1 <- rnorm(length(x1))
y2 <- rnorm(length(x2))
output$p <- renderPlot( plot_ly(x = ~x1, y = ~y1, text = paste(tm1), mode = 'markers'))
output$p1 <- renderPlot ( plot_ly(x = ~x1, y = ~y2,text = paste(tm2, "days  today"), mode = 'markers', color = '4'))

})
2
  • what means in the same window? in one plot? or in two div in screen? add code of you UI Commented Nov 30, 2016 at 7:30
  • in one plot only. Commented Nov 30, 2016 at 8:49

1 Answer 1

2

I think you should use subplots for achieve your goal. They are explained here: https://plot.ly/r/subplots/

The code of the first example is that:

library(plotly)
p1 <- plot_ly(economics, x = ~date, y = ~unemploy) %>%
  add_lines(name = ~"unemploy")
p2 <- plot_ly(economics, x = ~date, y = ~uempmed) %>%
  add_lines(name = ~"uempmed")
p <- subplot(p1, p2)

# Create a shareable link to your chart
# Set up API credentials: https://plot.ly/r/getting-started
chart_link <- plotly_POST(p, filename = "subplot/basic")
chart_link

Hope it helps:-)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy 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.