Merge branch 'replay-plot'

This commit is contained in:
Winston Chang
2016-02-19 13:57:38 -06:00
4 changed files with 222 additions and 123 deletions

View File

@@ -6,6 +6,16 @@ sortList <- function(x) {
x[sort(names(x))]
}
# Extract the print.ggplot function from inside of renderPlot. Yuck.
print_ggplot_expr <- Filter(function(x) {
is.call(x) &&
x[[1]] == as.name("<-") &&
x[[2]] == as.name("print.ggplot")
}, body(renderPlot))[[1]]
# This will create print.ggplot in the current environment
eval(print_ggplot_expr)
test_that("ggplot coordmap", {
dat <- data.frame(xvar = c(0, 5), yvar = c(10, 20))
@@ -17,7 +27,7 @@ test_that("ggplot coordmap", {
scale_x_continuous(expand = c(0, 0)) +
scale_y_continuous(expand = c(0, 0))
png(tmpfile)
m <- getGgplotCoordmap(p, 1)
m <- getGgplotCoordmap(print(p), 1)
dev.off()
# Check mapping vars
@@ -32,7 +42,7 @@ test_that("ggplot coordmap", {
# Scatterplot where aes() is declared in geom
p <- ggplot(dat, aes(xvar)) + geom_point(aes(y=yvar))
png(tmpfile)
m <- getGgplotCoordmap(p, 1)
m <- getGgplotCoordmap(print(p), 1)
dev.off()
# Check mapping vars
@@ -42,7 +52,7 @@ test_that("ggplot coordmap", {
# Plot with computed variable (histogram)
p <- ggplot(dat, aes(xvar)) + geom_histogram(binwidth=1)
png(tmpfile)
m <- getGgplotCoordmap(p, 1)
m <- getGgplotCoordmap(print(p), 1)
dev.off()
# Check mapping vars - no value for y
@@ -63,7 +73,7 @@ test_that("ggplot coordmap with facet_wrap", {
scale_y_continuous(expand = c(0, 0)) +
facet_wrap(~ g, ncol = 2)
png(tmpfile)
m <- getGgplotCoordmap(p, 1)
m <- getGgplotCoordmap(print(p), 1)
dev.off()
# Should have 3 panels
@@ -112,7 +122,7 @@ test_that("ggplot coordmap with facet_grid", {
# facet_grid horizontal
p1 <- p + facet_grid(. ~ g)
png(tmpfile)
m <- getGgplotCoordmap(p1, 1)
m <- getGgplotCoordmap(print(p1), 1)
dev.off()
# Should have 3 panels
@@ -149,7 +159,7 @@ test_that("ggplot coordmap with facet_grid", {
# facet_grid vertical
p1 <- p + facet_grid(g ~ .)
png(tmpfile)
m <- getGgplotCoordmap(p1, 1)
m <- getGgplotCoordmap(print(p1), 1)
dev.off()
# Should have 3 panels
@@ -197,7 +207,7 @@ test_that("ggplot coordmap with 2D facet_grid", {
p1 <- p + facet_grid(g ~ h)
png(tmpfile)
m <- getGgplotCoordmap(p1, 1)
m <- getGgplotCoordmap(print(p1), 1)
dev.off()
# Should have 4 panels