Skip to content

Commit 36b4361

Browse files
committed
Merge pull request #150 from ropensci/marianne-geom-text-colour
Let geom_text layer split into traces along colour
2 parents 5076e1e + 4dfca24 commit 36b4361

File tree

7 files changed

+43
-7
lines changed

7 files changed

+43
-7
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
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.15
4+
Version: 0.5.16
55
Authors@R: c(person("Chris", "Parmer", role = c("aut", "cre"),
66
email = "[email protected]"),
77
person("Scott", "Chamberlain", role = "aut",

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
0.5.16 -- 29 December 2014.
2+
3+
Support colour aesthetic in geom_text().
4+
15
0.5.15 -- 19 December 2014.
26

37
Use proper RCurlOptions in get_figure() method.

R/ggplotly.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ markLegends <-
5353
polygon=c("colour", "fill", "linetype", "size", "group"),
5454
bar=c("colour", "fill"),
5555
step=c("linetype", "size", "colour"),
56-
boxplot=c("x"))
56+
boxplot=c("x"),
57+
text=c("colour"))
5758

5859
markUnique <- as.character(unique(unlist(markLegends)))
5960

R/plotly-package.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#' \itemize{
88
#' \item Package: plotly
99
#' \item Type: Package
10-
#' \item Version: 0.5.15
10+
#' \item Version: 0.5.16
1111
#' \item Date: 2014-03-07
1212
#' \item License: MIT
1313
#' }

R/plotly.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ For more help, see https://plot.ly/R or contact <[email protected]>.")
8282

8383
# public attributes/methods that the user has access to
8484
pub <- list(username=username, key=key, filename="from api", fileopt=NULL,
85-
version="0.5.15")
85+
version="0.5.16")
8686
priv <- list()
8787

8888
pub$makecall <- function(args, kwargs, origin) {

R/trace_generation.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,8 +428,8 @@ geom2trace <- list(
428428
if (!is.null(params$size)) {
429429
L$textfont$size <- params$size
430430
}
431-
if (!is.null(data$colour)) {
432-
L$textfont$color <- data$colour
431+
if (!is.null(params$colour)) {
432+
L$textfont$color <- params$colour
433433
}
434434
L
435435
},

tests/testthat/test-ggplot-text.R

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
context("text")
1+
context("Text")
22

33
gg <- ggplot(mtcars, aes(x=wt, y=mpg, label=rownames(mtcars))) +
44
geom_text(size=18)
@@ -18,3 +18,34 @@ test_that("textsize is translated correctly", {
1818
})
1919

2020
save_outputs(gg, "text")
21+
22+
test_that("geom_text splits along colour", {
23+
mds <- data.frame(State=c("Alabama", "Alabama", "Alabama", "Alabama",
24+
"Arizona", "Arizona"),
25+
City=c("HUNTSVILLE", "MOBILE", "BIRMINGHAM", "MONTGOMERY",
26+
"TUCSON", "PEORIA"),
27+
coord.1=c(1.561284, 6.088862, 9.978292, 15.454877,
28+
23.225289, -7.283954),
29+
coord.2=c(0.2228790, 0.8343259, -3.6507234, -4.8520206,
30+
-0.4438650, 9.1252792),
31+
Division=c("East South Central", "East South Central",
32+
"East South Central", "East South Central",
33+
"Mountain", "Mountain"))
34+
35+
gg <- ggplot(mds) +
36+
geom_text(aes(x=coord.1, y=coord.2, label=City, colour=Division))
37+
38+
L <- gg2list(gg)
39+
40+
expect_equal(length(L), 3) # 2 traces + layout
41+
# Proper type and mode conversion
42+
expect_identical(L[[1]]$type, "scatter")
43+
expect_identical(L[[1]]$mode, "text")
44+
expect_identical(L[[2]]$type, "scatter")
45+
expect_identical(L[[2]]$mode, "text")
46+
# Right colour for each trace
47+
expect_identical(L[[1]]$textfont$color, "#F8766D")
48+
expect_identical(L[[2]]$textfont$color, "#00BFC4")
49+
50+
save_outputs(gg, "text-colour")
51+
})

0 commit comments

Comments
 (0)