Skip to content

Bug fixes for ggplot2 (> 1.0.1) #269

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 75 commits into from
Dec 18, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
3ea26ae
Fix backwards incompatible changes made to ggplot2 internals. Also, i…
cpsievert Aug 18, 2015
a14e357
fix ggplot_build2() definition
cpsievert Aug 20, 2015
67baf3d
new scales is on CRAN; another fix for ggplot_build2()
cpsievert Sep 4, 2015
b4427e0
attempt at fixing #268
cpsievert Sep 4, 2015
1503c1c
missing s
cpsievert Sep 9, 2015
fd0b05c
Merge branch 'master' of https://github.com/ropensci/plotly into fix-…
cpsievert Sep 14, 2015
57866b0
Merge branch 'images-test' of https://github.com/ropensci/plotly into…
cpsievert Sep 14, 2015
36956c4
maybe we now have to get paramter values from the data?
cpsievert Sep 14, 2015
f94dc5e
Just like plotly_build(). ggplotly() should tag special properties to…
cpsievert Sep 14, 2015
d565f30
Messing around with sizing
cpsievert Sep 14, 2015
5d2d6c7
Moar fixes for geom_point
cpsievert Sep 14, 2015
6b0d1dc
Tsting for a NA color is too specific
cpsievert Sep 14, 2015
2634b53
Write JSON to disk (instead of downloading figure from server) in ord…
cpsievert Sep 15, 2015
1e7d8af
Merge branch 'images-test' of https://github.com/ropensci/plotly into…
cpsievert Sep 15, 2015
52650f3
Don't run image examples
cpsievert Sep 15, 2015
2e130cd
More careful approach to 'unboxing' gg2list() output
cpsievert Sep 15, 2015
170723c
server can't handle empty keyword args
cpsievert Sep 15, 2015
53aa318
import stats::setNames
cpsievert Sep 15, 2015
6d43c3e
Bug fixes
cpsievert Sep 15, 2015
509e50f
hline/vline/abline are all paths, fixes for boxplot
cpsievert Sep 15, 2015
e5e49bb
merge conflict
cpsievert Sep 15, 2015
7a5826c
Mor fun with file naming
cpsievert Sep 16, 2015
520f75f
Test fixes for abline/hline/vline
cpsievert Sep 17, 2015
262d0a1
grab parameter defaults from data; test cleanup
cpsievert Sep 17, 2015
d812c84
boxplot hack no longer necessary
cpsievert Sep 18, 2015
08cbabf
no longer need to grab parameters from data within specific geoms
cpsievert Sep 18, 2015
1c47d1c
It's possible to have a character string represent a missing value
cpsievert Sep 18, 2015
483552a
ggplot2::geom_*() no longer allows passing arbitrary arguments
cpsievert Sep 18, 2015
b444d7b
It doesn't make sense to hard-code ggplot2 default values in tests
cpsievert Sep 18, 2015
22670ee
merge with htmlwidgets
cpsievert Oct 14, 2015
5d0697d
move Rserve and RSclient to DESCRIPTION
cpsievert Oct 14, 2015
ee227ea
merge with htmlwidgets
cpsievert Nov 1, 2015
e75355e
Merge branch 'htmlwidgets' of https://github.com/ropensci/plotly into…
cpsievert Nov 1, 2015
6c5441b
Utilize ggproto's new default_aes property; convert size more directly
cpsievert Nov 1, 2015
b52e69d
direction is not really an aesthetic
cpsievert Nov 1, 2015
811598a
remove bad tests
cpsievert Nov 1, 2015
50a180d
path size means width not area
cpsievert Nov 1, 2015
6149dcc
Merge branch 'master' of https://github.com/ropensci/plotly into fix-…
cpsievert Nov 3, 2015
703a159
update to latest roxygen
cpsievert Nov 9, 2015
164a6ad
new test table
cpsievert Nov 9, 2015
e990f4e
use env var to flag table building
cpsievert Nov 11, 2015
0c46429
merge with master
cpsievert Nov 20, 2015
e8a3390
fix merge mistake
cpsievert Nov 20, 2015
52fa33d
Merge branch 'master' of https://github.com/ropensci/plotly into fix-…
cpsievert Nov 30, 2015
e3ecaef
Better removal of asis class
cpsievert Nov 30, 2015
cb18360
Merge branch 'baobao-legend_name' of https://github.com/ropensci/plot…
cpsievert Dec 1, 2015
c13bcd1
more graceful test exit
cpsievert Dec 1, 2015
4914dea
merge with master
cpsievert Dec 1, 2015
ba21238
more modular boxing of special properties
cpsievert Dec 1, 2015
2749f03
Merge branch 'master' of https://github.com/ropensci/plotly into fix-…
cpsievert Dec 2, 2015
d38b4ea
merge conflicts
cpsievert Dec 9, 2015
d63fe06
fix many legend items test
cpsievert Dec 10, 2015
c4e2e82
consistent style
cpsievert Dec 10, 2015
e3cae85
ensure traces that fall outside the range of the scale are removed
cpsievert Dec 10, 2015
ad8379c
Merge branch 'marianne-fix-element-aes' into fix-ggplot2
cpsievert Dec 10, 2015
0d78f11
Merge branch 'baobao-geom_jitter' into fix-ggplot2
cpsievert Dec 10, 2015
e68c8b6
fix typo in test
cpsievert Dec 10, 2015
37965cd
Merge branch 'baobao-geom_jitter' into fix-ggplot2
cpsievert Dec 10, 2015
66aaac2
merge with master
cpsievert Dec 12, 2015
283e1a1
Merge branch 'master' of https://github.com/ropensci/plotly into fix-…
cpsievert Dec 12, 2015
c559098
merge conflicts for fix/box-fill
cpsievert Dec 12, 2015
b09d269
Merge branch 'master' of https://github.com/ropensci/plotly into fix-…
cpsievert Dec 12, 2015
2974cd3
merge conflicts
cpsievert Dec 13, 2015
b268980
Merge branch 'master' of https://github.com/ropensci/plotly into fix-…
cpsievert Dec 14, 2015
729429a
remove redundant save_output()
cpsievert Dec 14, 2015
ca04a32
be more careful when joining boxplot data
cpsievert Dec 14, 2015
d9446f2
unique test names
cpsievert Dec 14, 2015
8cd2da0
fix #341
cpsievert Dec 14, 2015
dc92b6b
Use plotly_POST() to host webgl plots in vignette
cpsievert Dec 14, 2015
50a8983
upgrade to plotlyjs 1.2.1
cpsievert Dec 15, 2015
9547683
CRAN version of ggplot2
cpsievert Dec 18, 2015
39267e1
Merge branch 'master' of https://github.com/ropensci/plotly into fix-…
cpsievert Dec 18, 2015
b0d123d
add rstudio project
cpsievert Dec 18, 2015
2c3f22c
require ggplot2 2.0
cpsievert Dec 18, 2015
20cfea7
ytrans is deprecated
cpsievert Dec 18, 2015
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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ Rapp.history
.RData
Makefile
.Rproj.user
*.Rproj
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Description: Easily translate ggplot2 graphs to an interactive web-based version
URL: https://plot.ly/r, https://github.com/ropensci/plotly
BugReports: https://github.com/ropensci/plotly/issues
Depends:
ggplot2
ggplot2 (>= 2.0.0)
Imports:
scales,
httr,
Expand Down
9 changes: 3 additions & 6 deletions R/build_function.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,10 @@ ggplot_build2 <- local({
g_b <- as.list(body(ggplot_build2))

# Find line where we want to insert new code
line_after <- quote(data <- calculate_stats(panel, data, layers))
idx <- vapply(g_b, identical, line_after, FUN.VALUE=TRUE)
idx <- which(idx)

idx <- grep("compute_statistic", as.character(g_b))
if (length(idx) != 1) {
warning("ggplotly() is not compatible with this version of ggplot2", call. = F)
} else {
warning("Unexpected ggplot2::ggplot_build() definition", call. = FALSE)
} else{
# Insert new code before that line
new_line <- quote(prestats.data <- data)
return_value <- quote(list(data=data, panel=panel, plot=plot,
Expand Down
9 changes: 6 additions & 3 deletions R/colour_conversion.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
#' @param alpha transparency alpha
#' @return hexadecimal colour value (if is.na(x), return "transparent" for compatibility with Plotly)
#' @export
toRGB <- function(x, alpha=1) {
if(is.null(x))return(x)
if (alpha!=1) {
toRGB <- function(x, alpha = 1) {
if (is.null(x)) return(x)
if (identical(x, "NA")) x <- NA
# as of ggplot2 version 1.1, an NA alpha is treated as though it's 1
if (is.na(alpha)) alpha <- 1
if (alpha != 1) {
rgb.matrix <- col2rgb(x, TRUE)
rgb.matrix["alpha", 1] <- alpha
ch.vector <- "rgba(%s)"
Expand Down
171 changes: 93 additions & 78 deletions R/corresp_one_one.R
Original file line number Diff line number Diff line change
@@ -1,92 +1,107 @@
# Convert R pch point codes to plotly "symbol" codes.
pch2symbol <- c("0"="square-open",
"1"="circle-open",
"2"="triangle-up-open",
"3"="cross-thin-open",
"4"="x-thin-open",
"5"="diamond-open",
"6"="triangle-down-open",
"7"="square-x-open",
"8"="asterisk-open",
"9"="diamond-x-open",
"10"="circle-cross-open",
"11"="hexagram-open",
"12"="square-cross-open",
"13"="circle-x-open",
"14"="square-open-dot",
"15"="square",
"16"="circle",
"17"="triangle-up",
"18"="diamond",
"19"="circle",
"20"="circle",
"21"="circle",
"22"="square",
"23"="diamond",
"24"="triangle-up",
"25"="triangle-down",
"32"="circle",
"35"="hash-open",
"42"="asterisk-open",
"43"="cross-thin-open",
"45"="line-ew-open",
"47"="line-ne-open",
"48"="circle-open",
"79"="circle-open",
"88"="x-thin-open",
"92"="line-nw-open",
"95"="line-ew-open",
"111"="circle-open",
"o"="circle-open",
"O"="circle-open",
"+"="cross-thin-open")
pch2symbol <- c(
"0" = "square-open",
"1" = "circle-open",
"2" = "triangle-up-open",
"3" = "cross-thin-open",
"4" = "x-thin-open",
"5" = "diamond-open",
"6" = "triangle-down-open",
"7" = "square-x-open",
"8" = "asterisk-open",
"9" = "diamond-x-open",
"10" = "circle-cross-open",
"11" = "hexagram-open",
"12" = "square-cross-open",
"13" = "circle-x-open",
"14" = "square-open-dot",
"15" = "square",
"16" = "circle",
"17" = "triangle-up",
"18" = "diamond",
"19" = "circle",
"20" = "circle",
"21" = "circle",
"22" = "square",
"23" = "diamond",
"24" = "triangle-up",
"25" = "triangle-down",
"32" = "circle",
"35" = "hash-open",
"42" = "asterisk-open",
"43" = "cross-thin-open",
"45" = "line-ew-open",
"47" = "line-ne-open",
"48" = "circle-open",
"79" = "circle-open",
"88" = "x-thin-open",
"92" = "line-nw-open",
"95" = "line-ew-open",
"111" = "circle-open",
"o" = "circle-open",
"O" = "circle-open",
"+" = "cross-thin-open"
)

# Convert ggplot2 aes to plotly "marker" codes.
aes2marker <- c(alpha="opacity",
colour="color",
size="size",
sizeref="sizeref",
sizemode="sizemode",
shape="symbol")

# Convert numeric line type.
numeric.lty <- c("0"="none",
"1"="solid",
"2"="dash",
"3"="dot",
"4"="dashdot",
"5"="longdash",
"6"="longdashdot")
numeric.lty <- c(
"0" = "none",
"1" = "solid",
"2" = "dash",
"3" = "dot",
"4" = "dashdot",
"5" = "longdash",
"6" = "longdashdot"
)

# Convert named line type.
named.lty <- c("blank"="none",
"solid"="solid",
"dashed"="dash",
"dotted"="dot",
"dotdash"="dashdot",
"longdash"="longdash",
"twodash"="longdashdot")
named.lty <- c(
"blank" = "none",
"solid" = "solid",
"dashed" = "dash",
"dotted" = "dot",
"dotdash" = "dashdot",
"longdash" = "longdash",
"twodash" = "longdashdot"
)

# Convert coded line type.
coded.lty <- c("22"="dash",
"42"="dot",
"44"="dashdot",
"13"="longdash",
"1343"="longdashdot",
"73"="dash",
"2262"="dotdash",
"12223242"="dotdash",
"F282"="dash",
"F4448444"="dash",
"224282F2"="dash",
"F1"="dash")
coded.lty <- c(
"22" = "dash",
"42" = "dot",
"44" = "dashdot",
"13" = "longdash",
"1343" = "longdashdot",
"73" = "dash",
"2262" = "dotdash",
"12223242" = "dotdash",
"F282" = "dash",
"F4448444" = "dash",
"224282F2" = "dash",
"F1" = "dash"
)

# Convert R lty line type codes to plotly "dash" codes.
lty2dash <- c(numeric.lty, named.lty, coded.lty)

# Convert ggplot2 aes to line parameters.
aes2line <- c(linetype="dash",
colour="color",
size="width",
direction="shape")
aes2line <- c(
linetype = "dash",
colour = "color",
size = "width"
)

aes2step <- c(
aes2line,
direction = "shape"
)

# Convert ggplot2 aes to plotly "marker" codes.
aes2marker <- c(
alpha = "opacity",
colour = "color",
size = "size",
shape = "symbol"
)

92 changes: 24 additions & 68 deletions R/ggplotly.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,41 +50,19 @@ ggplotly <- function(p = ggplot2::last_plot(), filename, fileopt,
now <- Sys.time()
the.epoch <- now - as.numeric(now)

default.marker.sizeref <- 1
marker.size.mult <- 10

marker.defaults <- list(alpha=1,
shape="16",
size=marker.size.mult,
sizeref=default.marker.sizeref,
sizemode="area",
colour="black")

line.defaults <- list(linetype="solid",
colour="black",
size=1,
direction="linear")

boxplot.defaults <- line.defaults
boxplot.defaults$colour <- "grey20"

ribbon.line.defaults <- line.defaults
ribbon.line.defaults$colour <- NA

polygon.line.defaults <- line.defaults
polygon.line.defaults$colour <- NA

# Convert R lty line type codes to plotly "dash" codes.
lty2dash <- c(numeric.lty, named.lty, coded.lty)

aesConverters <- list(
linetype=function(lty) {
lty2dash[as.character(lty)]
},
colour=function(col) {
toRGB(col)
},
size=identity,
# ggplot2 size is in millimeters. plotly is in pixels. To do this correctly,
# we need to know PPI/DPI of the display. I'm not sure of a decent way to do that
# from R, but it seems 96 is a reasonable assumption.
size=function(mm) {
(mm * 96) / 25.4
},
sizeref=identity,
sizemode=identity,
alpha=identity,
Expand Down Expand Up @@ -119,6 +97,11 @@ markUnique <- as.character(unique(unlist(markLegends)))
markSplit <- markLegends
markSplit$boxplot <- "x"

# obtain the "type" of geom/position/etc.
type <- function(x, y) {
sub(y, "", tolower(class(x[[y]])[[1]]))
}

guide_names <- function(p, aes = c("shape", "fill", "alpha", "area",
"color", "colour", "size", "linetype")) {
sc <- as.list(p$scales)$scales
Expand All @@ -136,21 +119,8 @@ guide_names <- function(p, aes = c("shape", "fill", "alpha", "area",
#' @return figure object (list with names "data" and "layout").
#' @export
gg2list <- function(p) {
if(length(p$layers) == 0) {
stop("No layers in plot")
}
# Always use identity size scale so that plot.ly gets the real
# units for the size variables.
original.p <- p
p <- tryCatch({
# this will be an error for discrete variables.
suppressMessages({
ggplot_build(p+scale_size_continuous())
p+scale_size_identity()
})
},error=function(e){
p
})
# ggplot now applies geom_blank() (instead of erroring) when no layers exist
if (length(p$layers) == 0) p <- p + geom_blank()
layout <- list()
trace.list <- list()

Expand Down Expand Up @@ -188,7 +158,7 @@ gg2list <- function(p) {
misc[[misc.name]][[a]] <- tryCatch({
fun <- get(fun.name)
suppressMessages({
with.scale <- original.p + fun()
with.scale <- p + fun()
})
ggplot_build(with.scale)
TRUE
Expand Down Expand Up @@ -307,7 +277,7 @@ gg2list <- function(p) {
# This extracts essential info for this geom/layer.
traces <- layer2traces(L, df, misc)

possible.legends <- markLegends[[L$geom$objname]]
possible.legends <- markLegends[[type(L, "geom")]]
actual.legends <- possible.legends[possible.legends %in% names(L$mapping)]
layer.legends[[paste(i)]] <- actual.legends

Expand Down Expand Up @@ -405,7 +375,7 @@ gg2list <- function(p) {
trace.name.map <- c()
for(xy in c("x","y")){
ax.list <- list()
coord.lim <- p$coord$limits[[xy]]
coord.lim <- p$coordinates$limits[[xy]] %||% p$scales$get_scales(xy)$limits
if(is.numeric(coord.lim)){
## TODO: maybe test for more exotic coord specification types
## involving NA, Inf, etc?
Expand Down Expand Up @@ -525,6 +495,10 @@ gg2list <- function(p) {
# translate to plotly:
!is.blank(s("axis.line.%s"))
layout[[s("%saxis")]] <- ax.list
# remove traces that are outside the range of (discrete) scales
nms <- unlist(lapply(traces, "[[", "name"))
if (is.discrete(ax.list$range) && !is.null(nms))
trace.list <- trace.list[nms %in% ax.list$range]
}
# copy [x/y]axis to [x/y]axisN and set domain, range, etc. for each
xaxis.title <- layout$xaxis$title
Expand Down Expand Up @@ -955,7 +929,8 @@ gg2list <- function(p) {
# each axis.
flipped.traces <- named.traces
flipped.layout <- layout
if("flip" %in% attr(built$plot$coordinates, "class")){
coord_cl <- sub("coord", "", tolower(class(built$plot$coordinates)))
if("flip" %in% coord_cl){
if(!inherits(p$facet, "null")){
stop("coord_flip + facet conversion not supported")
}
Expand All @@ -974,25 +949,6 @@ gg2list <- function(p) {
}

l <- list(data = flipped.traces, layout = flipped.layout)

for (i in seq_along(l$data)) {
d <- l$data[[i]]
# jsonlite converts NULL to {} and NA to null (plotly prefers null to {})
# https://github.com/jeroenooms/jsonlite/issues/29
d[sapply(d, is.null)] <- NA
# When auto_unbox is T in jsonlite::toJSON() it doesn't unbox objects of
# class AsIs. We use this in plotly::to_JSON() and tag special fields such as
# x/y/etc so that they don't get unboxed when they are of length 1.
# unfortunately, this conflicts when using I() in qplot. For example,
# qplot(1:10, 1:10, size = I(10))
idx <- sapply(d, inherits, "AsIs")
for (j in which(idx)) l$data[[i]][[j]] <- unclass(l$data[[i]][[j]])
# some object keys require an array, even if length one
# one way to ensure atomic vectors of length 1 are not automatically unboxed,
# by to_JSON(), is to attach a class of AsIs (via I())
idx <- names(d) %in% get_boxed() & sapply(d, length) == 1
if (any(idx)) l$data[[i]][idx] <- lapply(d[idx], I)
}
structure(l, class = "plotly")


structure(add_boxed(rm_asis(l)), class = "plotly")
}
Loading