From 40511e2a286c1ff38c25f8e115e797a64244dadf Mon Sep 17 00:00:00 2001 From: Toby Dylan Hocking Date: Fri, 27 Feb 2015 16:52:06 -0500 Subject: [PATCH 1/5] ylim test fails --- tests/testthat/test-ggplot-ylim.R | 33 +++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 tests/testthat/test-ggplot-ylim.R diff --git a/tests/testthat/test-ggplot-ylim.R b/tests/testthat/test-ggplot-ylim.R new file mode 100644 index 0000000000..3fe16163c7 --- /dev/null +++ b/tests/testthat/test-ggplot-ylim.R @@ -0,0 +1,33 @@ +context("ggplot ylim") + +## http://www.cookbook-r.com/Graphs/Bar_and_line_graphs_%28ggplot2%29/ + +df <- data.frame(time = factor(c("Lunch","Dinner"), levels=c("Lunch","Dinner")), + total_bill = c(14.89, 17.23)) + +gg.ylim <- + ggplot(data=df, aes(x=time, y=total_bill, group=1)) + + geom_line() + + geom_point() + + ylim(0, max(df$total_bill)) + + xlab("Time of day") + ylab("Total bill") + + ggtitle("Average bill for 2 people") + +expect_traces <- function(gg, n.traces, name){ + stopifnot(is.ggplot(gg)) + stopifnot(is.numeric(n.traces)) + save_outputs(gg, paste0("ylim-", name)) + L <- gg2list(gg) + is.trace <- names(L) == "" + all.traces <- L[is.trace] + no.data <- sapply(all.traces, function(tr) { + is.null(tr[["x"]]) && is.null(tr[["y"]]) + }) + has.data <- all.traces[!no.data] + expect_equal(length(has.data), n.traces) + list(traces=has.data, kwargs=L$kwargs) +} + +test_that("ylim is respected for 1 trace", { + expect_traces(gg.ylim, 1, "one-trace") +}) From df927ee71e65b5d959bcd75470a7fad9080f7d7d Mon Sep 17 00:00:00 2001 From: Toby Dylan Hocking Date: Fri, 27 Feb 2015 17:03:16 -0500 Subject: [PATCH 2/5] expect ylim --- tests/testthat/test-ggplot-ylim.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test-ggplot-ylim.R b/tests/testthat/test-ggplot-ylim.R index 3fe16163c7..3c749d861b 100644 --- a/tests/testthat/test-ggplot-ylim.R +++ b/tests/testthat/test-ggplot-ylim.R @@ -29,5 +29,7 @@ expect_traces <- function(gg, n.traces, name){ } test_that("ylim is respected for 1 trace", { - expect_traces(gg.ylim, 1, "one-trace") + info <- expect_traces(gg.ylim, 1, "one-trace") + expected.ylim <- c(0, max(df$total_bill)) + expect_equal(info$kwargs$layout$yaxis$range, expected.ylim) }) From 618456d6e5d71de59481c5b1681db793a77f26c3 Mon Sep 17 00:00:00 2001 From: Toby Dylan Hocking Date: Fri, 27 Feb 2015 17:04:08 -0500 Subject: [PATCH 3/5] only use trace.order.list for axes with type=category --- R/ggplotly.R | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/R/ggplotly.R b/R/ggplotly.R index 3b2cf9e378..e5e62e4359 100644 --- a/R/ggplotly.R +++ b/R/ggplotly.R @@ -305,12 +305,28 @@ gg2list <- function(p){ ax.list$tickangle <- -tick.text$angle } ax.list$tickfont <- theme2font(tick.text) + + ## determine axis type first, since this information is used later + ## (trace.order.list is only used for type=category). + title.text <- e(s("axis.title.%s")) + ax.list$titlefont <- theme2font(title.text) + ax.list$type <- if(misc$is.continuous[[xy]]){ + "linear" + }else if(misc$is.discrete[[xy]]){ + "category" + }else if(misc$is.date[[xy]] || misc$is.datetime[[xy]]){ + "date" + }else{ + stop("unrecognized data type for ", xy, " axis") + } # Translate axes labels. scale.i <- which(p$scales$find(xy)) ax.list$title <- if(length(scale.i)){ sc <- p$scales$scales[[scale.i]] - trace.order.list[[xy]] <- sc$limits + if(ax.list$type == "category"){ + trace.order.list[[xy]] <- sc$limits + } trace.name.map[sc$breaks] <- sc$labels if (is.null(sc$breaks)) { ax.list$showticklabels <- FALSE @@ -346,18 +362,6 @@ gg2list <- function(p){ p$labels[[xy]] } - title.text <- e(s("axis.title.%s")) - ax.list$titlefont <- theme2font(title.text) - ax.list$type <- if(misc$is.continuous[[xy]]){ - "linear" - }else if(misc$is.discrete[[xy]]){ - "category" - }else if(misc$is.date[[xy]] || misc$is.datetime[[xy]]){ - "date" - }else{ - stop("unrecognized data type for ", xy, " axis") - } - ax.list$zeroline <- FALSE # ggplot2 plots do not show zero lines # Lines drawn around the plot border. ax.list$showline <- !is.blank("panel.border", TRUE) From db1da930aa08c0e810a221a1c63d24eceb5fc0e0 Mon Sep 17 00:00:00 2001 From: Toby Dylan Hocking Date: Mon, 2 Mar 2015 16:59:31 -0500 Subject: [PATCH 4/5] spacing before/after if/else --- R/ggplotly.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/R/ggplotly.R b/R/ggplotly.R index e5e62e4359..ba6acaef07 100644 --- a/R/ggplotly.R +++ b/R/ggplotly.R @@ -310,13 +310,13 @@ gg2list <- function(p){ ## (trace.order.list is only used for type=category). title.text <- e(s("axis.title.%s")) ax.list$titlefont <- theme2font(title.text) - ax.list$type <- if(misc$is.continuous[[xy]]){ + ax.list$type <- if (misc$is.continuous[[xy]]){ "linear" - }else if(misc$is.discrete[[xy]]){ + } else if (misc$is.discrete[[xy]]){ "category" - }else if(misc$is.date[[xy]] || misc$is.datetime[[xy]]){ + } else if (misc$is.date[[xy]] || misc$is.datetime[[xy]]){ "date" - }else{ + } else { stop("unrecognized data type for ", xy, " axis") } From e9496476f1c74ae67a7929a1258c1a6ad8e0ea5c Mon Sep 17 00:00:00 2001 From: Toby Dylan Hocking Date: Mon, 2 Mar 2015 16:59:41 -0500 Subject: [PATCH 5/5] version --- DESCRIPTION | 2 +- NEWS | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index c6ec3ebd62..cfdb548b5c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: plotly Type: Package Title: Interactive, publication-quality graphs online. -Version: 0.5.21 +Version: 0.5.22 Authors@R: c(person("Chris", "Parmer", role = c("aut", "cre"), email = "chris@plot.ly"), person("Scott", "Chamberlain", role = "aut", diff --git a/NEWS b/NEWS index c5d1e6d708..21360e5661 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,7 @@ +0.5.22 -- 2 March 2015. + +Fixes for ylim() #171. + 0.5.21 -- 23 February 2015. Fixes for error bars and tick marks.