suppressPackageStartupMessages(library(metricsgraphics))
suppressPackageStartupMessages(library(htmltools))
suppressPackageStartupMessages(library(dplyr))
plots <- lapply(1:7, function(x) {
mjs_plot(rnorm(10000, mean=x/2, sd=x), width=300, height=300, linked=TRUE) %>%
mjs_histogram(bar_margin=2) %>%
mjs_labs(x_label=sprintf("Plot %d", x))
})
moar_plots <- lapply(1:7, function(x) {
mjs_plot(rbeta(10000, x, x), width=300, height=300, linked=TRUE) %>%
mjs_histogram(bar_margin=2) %>%
mjs_labs(x_label=sprintf("Plot %d", x))
})
mjs_grid(plots)
mjs_grid(moar_plots, nrow=4, ncol=3, widths=c(rep(0.33, 3)))
tips <- reshape2::tips
a <- tips %>%
mutate(percent=tip/total_bill,
day=factor(day, levels=c("Thur", "Fri", "Sat", "Sun"), ordered=TRUE)) %>%
group_by(sex, day) %>%
do( plot={ x_label <- sprintf("Total Bill (%s)", unique(.$sex))
y_label <- sprintf("Tip %% (%s)", unique(.$day))
mjs_plot(., x=total_bill, y=percent, width="250px", height="250px", left=100) %>%
mjs_point() %>%
mjs_labs(x_label=x_label, y_label=y_label) })
mjs_grid(a$plot, ncol=4, nrow=2, widths=c(rep(0.5, 2)))
tips <- reshape2::tips
a <- tips %>%
mutate(percent=tip/total_bill,
day=factor(day, levels=c("Thur", "Fri", "Sat", "Sun"), ordered=TRUE)) %>%
group_by(day) %>%
do( plot={ day_label <- unique(.$day)
mjs_plot(., x=total_bill, y=percent, width="300px", height="300px", left=100) %>%
mjs_point(color_accessor=sex, color_type="category") %>%
mjs_labs(x_label=sprintf("Total Bill (%s)", day_label), y_label="Tip %") })
mjs_grid(a$plot, ncol=2, nrow=2, widths=c(0.5, 0.5))