Skip to content

Support alpha transparency in geom_area #164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 9, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: plotly
Type: Package
Title: Interactive, publication-quality graphs online.
Version: 0.5.19
Version: 0.5.20
Authors@R: c(person("Chris", "Parmer", role = c("aut", "cre"),
email = "[email protected]"),
person("Scott", "Chamberlain", role = "aut",
Expand Down
5 changes: 5 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
0.5.20 -- 9 February 2015.

Add alpha transparency to fill conversion.
Let geom_area support colour and fill aesthetics.

0.5.19 -- 23 January 2015.

Support class conversion such as as.Date() within ggplot code.
Expand Down
7 changes: 4 additions & 3 deletions R/colour_conversion.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' Convert R colours to RGBA hexadecimal colour values
#' @param x character for colour, for example: "white"
#' @param alpha alpha
#' @param alpha transparency alpha
#' @return hexadecimal colour value (if is.na(x), return "transparent" for compatibility with Plotly)
#' @export
toRGB <- function(x, alpha=1) {
Expand All @@ -20,7 +20,8 @@ toRGB <- function(x, alpha=1) {

#' Use default ggplot colour for fill (gray20) if not declared
#' @param x character for colour
#' @param alpha transparency alpha
#' @return hexadecimal colour value
toFill <- function(x) {
ifelse(!is.null(x), toRGB(x), toRGB("gray20"))
toFill <- function(x, alpha=1) {
ifelse(!is.null(x), toRGB(x, alpha), toRGB("gray20", alpha))
}
1 change: 1 addition & 0 deletions R/ggplotly.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ markLegends <-
path=c("linetype", "size", "colour", "shape"),
polygon=c("colour", "fill", "linetype", "size", "group"),
bar=c("colour", "fill"),
area=c("colour", "fill"),
step=c("linetype", "size", "colour"),
boxplot=c("x"),
text=c("colour"))
Expand Down
2 changes: 1 addition & 1 deletion R/plotly-package.r
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#' \itemize{
#' \item Package: plotly
#' \item Type: Package
#' \item Version: 0.5.19
#' \item Version: 0.5.20
#' \item Date: 2014-03-07
#' \item License: MIT
#' }
Expand Down
2 changes: 1 addition & 1 deletion R/plotly.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ For more help, see https://plot.ly/R or contact <[email protected]>.")

# public attributes/methods that the user has access to
pub <- list(username=username, key=key, filename="from api", fileopt=NULL,
version="0.5.19")
version="0.5.20")
priv <- list()

pub$makecall <- function(args, kwargs, origin) {
Expand Down
3 changes: 2 additions & 1 deletion R/trace_generation.R
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,8 @@ geom2trace <- list(
type="scatter",
line=paramORdefault(params, aes2line, ribbon.line.defaults),
fill="tozeroy",
fillcolor=toFill(params$fill))
fillcolor=toFill(params$fill, ifelse(is.null(params$alpha), 1,
params$alpha)))
},
ribbon=function(data, params) {
list(x=c(data$x[1], data$x, rev(data$x)),
Expand Down
11 changes: 11 additions & 0 deletions tests/testthat/test-ggplot-area.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,14 @@ test_that("sanity check for geom_area", {
})

save_outputs(ar, "area")

# Test alpha transparency in fill color
gg <- ggplot(huron) + geom_area(aes(x=year, y=level), alpha=0.4)
L <- gg2list(gg)

test_that("transparency alpha in geom_area is converted", {
expect_identical(L[[1]]$line$color, "transparent")
expect_identical(L[[1]]$fillcolor, "rgba(51,51,51,0.4)")
})

save_outputs(gg, "area-fillcolor")