Skip to content

Commit 7382c87

Browse files
committed
Merge pull request #133 from ropensci/marianne-let-bargarp
Let bargap adapt and fix x-labels in category histograms
2 parents e53047b + 9b6abae commit 7382c87

File tree

5 files changed

+15
-5
lines changed

5 files changed

+15
-5
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ R/.Rhistory
22
Rapp.history
33
/Karthik_local.R
44
*~
5-
.Rhistory
5+
.Rhistory
6+
.RData
7+
Makefile

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: plotly
22
Type: Package
33
Title: Interactive, publication-quality graphs online.
4-
Version: 0.5.4
4+
Version: 0.5.5
55
Authors@R: c(person("Chris", "Parmer", role = c("aut", "cre"),
66
email = "[email protected]"),
77
person("Scott", "Chamberlain", role = "aut",

NEWS

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
0.5.5 -- 24 October 2014.
2+
3+
Support category histograms (with factors).
4+
15
0.5.4 -- 22 October 2014.
26

37
Support conversion of geom_vline().

R/trace_generation.R

+4-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ layer2traces <- function(l, d, misc) {
2121
barmode <- "group"
2222
if (g$geom == "bar" || g$geom == "histogram") {
2323
if (l$stat$objname == "bin") {
24-
bargap <- 0
2524
if (g$geom != "histogram") {
2625
warning("You may want to use geom_histogram.")
2726
}
@@ -67,13 +66,15 @@ layer2traces <- function(l, d, misc) {
6766
"%Y-%m-%d %H:%M:%S")
6867
} else if (inherits(data.vec, "factor")) {
6968
## Re-order data so that Plotly gets it right from ggplot2.
70-
g$data <- g$data[order(g$data[[a]]),]
69+
g$data <- g$data[order(g$data[[a]]), ]
7170
data.vec <- data.vec[match(g$data[[a]], as.numeric(data.vec))]
72-
g$prestats.data <- g$prestats.data[order(g$prestats.data[[a]]),]
71+
g$prestats.data <- g$prestats.data[order(g$prestats.data[[a]]), ]
7372
pdata.vec <- pdata.vec[match(g$prestats.data[[a]],
7473
as.numeric(pdata.vec))]
7574
if (length(pdata.vec) == length(data.vec))
7675
pdata.vec <- data.vec
76+
if (!is.factor(pdata.vec))
77+
pdata.vec <- g$prestats.data[[paste0(a, ".name")]]
7778
}
7879
g$data[[a]] <- data.vec
7980
g$prestats.data[[a]] <- pdata.vec

tests/testthat/test-ggplot-histogram.R

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ test_that("default position is translated to barmode=stack", {
88
L <- gg2list(hist)
99
expect_equal(length(L), 2)
1010
expect_identical(L$kwargs$layout$barmode, "stack")
11+
expect_identical(L$kwargs$layout$xaxis$type, "category")
12+
expect_identical(L[[1]]$type, "histogram")
13+
expect_true(L[[1]]$x[1] %in% c("CDN", "MEX", "USA"))
1114

1215
save_outputs(hist, "histogram-barmodestack")
1316
})

0 commit comments

Comments
 (0)