Skip to content

Commit 329587d

Browse files
committed
Merge pull request #164 from ropensci/marianne-area-colour
Support alpha transparency in geom_area
2 parents 3463714 + 8928abd commit 329587d

File tree

8 files changed

+26
-7
lines changed

8 files changed

+26
-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.19
4+
Version: 0.5.20
55
Authors@R: c(person("Chris", "Parmer", role = c("aut", "cre"),
66
email = "[email protected]"),
77
person("Scott", "Chamberlain", role = "aut",

NEWS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
0.5.20 -- 9 February 2015.
2+
3+
Add alpha transparency to fill conversion.
4+
Let geom_area support colour and fill aesthetics.
5+
16
0.5.19 -- 23 January 2015.
27

38
Support class conversion such as as.Date() within ggplot code.

R/colour_conversion.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#' Convert R colours to RGBA hexadecimal colour values
22
#' @param x character for colour, for example: "white"
3-
#' @param alpha alpha
3+
#' @param alpha transparency alpha
44
#' @return hexadecimal colour value (if is.na(x), return "transparent" for compatibility with Plotly)
55
#' @export
66
toRGB <- function(x, alpha=1) {
@@ -20,7 +20,8 @@ toRGB <- function(x, alpha=1) {
2020

2121
#' Use default ggplot colour for fill (gray20) if not declared
2222
#' @param x character for colour
23+
#' @param alpha transparency alpha
2324
#' @return hexadecimal colour value
24-
toFill <- function(x) {
25-
ifelse(!is.null(x), toRGB(x), toRGB("gray20"))
25+
toFill <- function(x, alpha=1) {
26+
ifelse(!is.null(x), toRGB(x, alpha), toRGB("gray20", alpha))
2627
}

R/ggplotly.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ markLegends <-
5252
path=c("linetype", "size", "colour", "shape"),
5353
polygon=c("colour", "fill", "linetype", "size", "group"),
5454
bar=c("colour", "fill"),
55+
area=c("colour", "fill"),
5556
step=c("linetype", "size", "colour"),
5657
boxplot=c("x"),
5758
text=c("colour"))

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.19
10+
#' \item Version: 0.5.20
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.19")
85+
version="0.5.20")
8686
priv <- list()
8787

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

R/trace_generation.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,8 @@ geom2trace <- list(
556556
type="scatter",
557557
line=paramORdefault(params, aes2line, ribbon.line.defaults),
558558
fill="tozeroy",
559-
fillcolor=toFill(params$fill))
559+
fillcolor=toFill(params$fill, ifelse(is.null(params$alpha), 1,
560+
params$alpha)))
560561
},
561562
ribbon=function(data, params) {
562563
list(x=c(data$x[1], data$x, rev(data$x)),

tests/testthat/test-ggplot-area.R

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,14 @@ test_that("sanity check for geom_area", {
1515
})
1616

1717
save_outputs(ar, "area")
18+
19+
# Test alpha transparency in fill color
20+
gg <- ggplot(huron) + geom_area(aes(x=year, y=level), alpha=0.4)
21+
L <- gg2list(gg)
22+
23+
test_that("transparency alpha in geom_area is converted", {
24+
expect_identical(L[[1]]$line$color, "transparent")
25+
expect_identical(L[[1]]$fillcolor, "rgba(51,51,51,0.4)")
26+
})
27+
28+
save_outputs(gg, "area-fillcolor")

0 commit comments

Comments
 (0)