Two screens in the RStudio Viewer panel

Can I simultaneously view two dygraphin the RStudio Viewer panel?

I am updating an old function that creates two time series graphs (using ggplot2) stacked one above the other (using gridExtra::grid.arrange(ggp1, ggp2)). I want to use cool dygraph, and the change is quite simple, ..., except that I would like to view both graphs simultaneously in the RStudio Viewer panel.

You can view one chart at a time. Indeed, "If you call dygraphin RStudio, then its output appears in the Viewer panel . " But I could not find a trick to display both stories at the same time. And I want this because I want to use a convenient synchronization functiondygraph

For an example of reproducibility, here is an example of what I am doing.

library(dygraphs)   
dygraph(mdeaths, group = "ensync")
dygraph(fdeaths, group = "ensync")

But each of them is a new call in the R Console, and then the first view is displayed in the viewer and immediately replaces it with the second.

The only workaround I found was to put it in an RMarkdown document and write everything. But I do not like it. It would be more convenient for me to directly display it in the RStudio Viewer panel.

Any ideas?

+4
source share
3 answers

Using the package htmltools, insert two dygraphin tagListand use the function browsable()to plot both graphs in the viewer:

library(dygraphs)
library(htmltools)

browsable(
  tagList(
    dygraph(mdeaths, group = "ensync", height = 200, width = "100%"),
    dygraph(fdeaths, group = "ensync", height = 200, width = "100%")
    )
  )

Perhaps the code is more readable using the magrittrforward-pipe statement :

library(dygraphs)
library(htmltools)
library(magrittr)

dygraph(mdeaths, group = "ensync", height = 200, width = "100%") %>%
  tagList(dygraph(fdeaths, group = "ensync", height = 200, width = "100%")) %>%
  browsable()
+6

dygraphs, zoo plotly

(i) zoo ts data.frame

library(zoo)
m.dat <- data.frame(date=as.Date(as.yearmon(time(mdeaths))), Deaths=as.matrix(mdeaths), Sex="M")
f.dat <- data.frame(date=as.Date(as.yearmon(time(fdeaths))), Deaths=as.matrix(fdeaths), Sex="F")
dat <- rbind(m.dat, f.dat)

(ii) ggplot2

p <- ggplot(dat, aes(x=date, y=Deaths, group=Sex, colour=Sex)) + geom_line()

enter image description here

(iii) plotly:: ggplotly,

library(plotly)
ggplotly(p)

.

enter image description here

0

, "" RStudio, , , , . , , , .

0

All Articles