Description Usage Arguments Note Examples
Create a Trelliscope Display
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
x |
an object to create at trelliscope display for |
name |
name of the display |
group |
group that the display belongs to |
panel_col |
optional string specifying the column to use for panels (if there are multiple plot columns in |
desc |
optional text description of the display |
md_desc |
optional string of markdown that will be shown in the viewer for additional context about the display |
path |
the base directory of the trelliscope application |
height |
height in pixels of each panel |
width |
width in pixels of each panel |
auto_cog |
should auto cogs be computed (if possible)? |
state |
the initial state the display will open in |
nrow |
the number of rows of panels to display by default |
ncol |
the number of columns of panels to display by default |
jsonp |
should json for display object be jsonp (TRUE) or json (FALSE)? |
split_sig |
optional string that specifies the "signature" of the data splitting. If not specified, this is calculated as the md5 hash of the sorted unique facet variables. This is used to identify "related displays" - different displays that are based on the same faceting scheme. This parameter should only be specified manually if a display's faceting is mostly similar to another display's. |
self_contained |
should the Trelliscope display be a self-contained html document? (see note) |
thumb |
should a thumbnail be created? |
Note that self_contained
is severely limiting and should only be used in cases where you would either like your display to show up in the RStudio viewer pane, in an interactive R Markdown Notebook, or in a self-contained R Markdown html document.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | ## Not run:
library(dplyr)
library(tidyr)
library(purrr)
library(plotly)
library(ggplot2)
# tidyverse + plotly
d <- mpg %>%
nest(data = !one_of(c("manufacturer", "class"))) %>%
mutate(
mean_city_mpg = map_dbl(data, ~ mean(.$cty)),
panel = map_plot(data, function(x) {
plot_ly(data = x, x = ~cty, y = ~hwy,
type = "scatter", mode = "markers")
})
)
d %>% trelliscope(name = "city_vs_highway_mpg")
# set default layout
d %>% trelliscope(name = "city_vs_highway_mpg", nrow = 2, ncol = 3)
# set the output path for where files will be stored
my_displays <- tempfile()
d %>% trelliscope(name = "city_vs_highway_mpg", path = my_displays)
# multiple displays can be added to the same path and all will be available in the viewer
d %>% trelliscope(name = "city_vs_highway_mpg2", path = my_displays)
# ordering the data frame will set default sort order of the display
d %>%
arrange(-mean_city_mpg) %>%
trelliscope(name = "city_vs_highway_mpg")
# tidyverse + ggplot2
mpg %>%
nest(data = !one_of(c("manufacturer", "class"))) %>%
mutate(
panel = map_plot(data, ~
qplot(cty, hwy, data = .) + xlab("cty") + ylab("hwy") +
xlim(7, 37) + ylim(9, 47) + theme_bw())) %>%
trelliscope(name = "tidy_gg")
# computing additional cognostics
mpg_cog <- mpg %>%
nest(data = !one_of(c("manufacturer", "class"))) %>%
mutate(
cogs = map_cog(data, ~ tibble(
mean_city_mpg = mean(.$cty),
mean_hwy_mpg = mean(.$hwy),
most_common_drv = tail(names(table(.$drv)), 1)
))
)
# computing additional cognostics explicitly using cog()
# so we can specify descriptions, etc.
mpg_cog2 <- mpg %>%
nest(data = !one_of(c("manufacturer", "class"))) %>%
mutate(
cogs = map_cog(data, ~ tibble(
mean_city_mpg = cog(mean(.$cty), desc = "Mean city mpg"),
mean_hwy_mpg = cog(mean(.$hwy), desc = "Mean highway mpg"),
most_common_drv = cog(tail(names(table(.$drv)), 1), desc = "Most common drive type")
)),
panel = map_plot(data, function(x) {
plot_ly(data = x, x = ~cty, y = ~hwy,
type = "scatter", mode = "markers") %>%
layout(
xaxis = list(range = c(9, 47)),
yaxis = list(range = c(7, 37)))
})
)
mpg_cog2 %>%
trelliscope(name = "city_vs_highway_mpg", nrow = 1, ncol = 2)
## End(Not run)
|
Attaching package: ‘dplyr’
The following objects are masked from ‘package:stats’:
filter, lag
The following objects are masked from ‘package:base’:
intersect, setdiff, setequal, union
Loading required package: ggplot2
Attaching package: ‘plotly’
The following object is masked from ‘package:ggplot2’:
last_plot
The following object is masked from ‘package:stats’:
filter
The following object is masked from ‘package:graphics’:
layout
Warning message:
`arrange_()` is deprecated as of dplyr 0.7.0.
Please use `arrange()` instead.
See vignette('programming') for more help
This warning is displayed once every 8 hours.
Call `lifecycle::last_warnings()` to see where this warning was generated.
Warning message:
`filter_()` is deprecated as of dplyr 0.7.0.
Please use `filter()` instead.
See vignette('programming') for more help
This warning is displayed once every 8 hours.
Call `lifecycle::last_warnings()` to see where this warning was generated.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.