From 36ad7a9f7b64525217e764759f54bed08eab5267 Mon Sep 17 00:00:00 2001 From: Carson Sievert Date: Mon, 21 Nov 2016 10:51:12 -0600 Subject: [PATCH 1/2] add initial support for translation of GeomEdgePath/GeomEdgeDensity/GeomTreemap --- NAMESPACE | 3 +++ R/plotly.R | 58 +++++++++++++++++++++++++++++++++++++++++++ man/geom_node_text.Rd | 2 +- 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 R/plotly.R diff --git a/NAMESPACE b/NAMESPACE index c37d917f..f22842ba 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -5,6 +5,9 @@ S3method(createLayout,default) S3method(createLayout,dendrogram) S3method(createLayout,igraph) S3method(getConnections,default) +S3method(to_basic,GeomEdgeDensity) +S3method(to_basic,GeomEdgePath) +S3method(to_basic,GeomTreemap) S3method(treeApply,default) S3method(treeApply,dendrogram) S3method(treeApply,igraph) diff --git a/R/plotly.R b/R/plotly.R new file mode 100644 index 00000000..d5a05ee5 --- /dev/null +++ b/R/plotly.R @@ -0,0 +1,58 @@ +# --------------------------------------------------------------------------- +# Translations for R/geom_axis_hive.R +# --------------------------------------------------------------------------- + +# TODO: waiting for an example + +# --------------------------------------------------------------------------- +# Translations for R/geom_edge.R +# --------------------------------------------------------------------------- + +toPath <- function(data, prestats_data, layout, params, p, ...) { + prefix_class(data, "GeomPath") +} + +#' @export +to_basic.GeomEdgePath <- toPath + +#' @export +to_basic.GeomEdgeSegment <- toPath + +#' @export +to_basic.GeomEdgeBezier <- toPath + +#' @export +to_basic.GeomEdgeBspline <- toPath + +# --------------------------------------------------------------------------- +# Translations for R/geom_edge_density.R +# --------------------------------------------------------------------------- + +#' @export +to_basic.GeomEdgeDensity <- function(data, prestats_data, layout, params, p, ...) { + # avoid a weird precision issue + data$density[data$density < 0.005] <- 0 + data$fill_plotlyDomain <- data$density + data$fill <- toRGB( + data$edge_fill, scales::rescale(data$density) + ) + prefix_class(data, "GeomTile") +} + +# --------------------------------------------------------------------------- +# Translations for R/geom_treemap.R +# --------------------------------------------------------------------------- + +#' @export +to_basic.GeomTreemap <- getFromNamespace("to_basic.GeomRect", asNamespace("plotly")) + + +# --------------------------------------------------------------------------- +# Helper functions +# --------------------------------------------------------------------------- + +prefix_class <- function(x, y) { + structure(x, class = unique(c(y, class(x)))) +} + + diff --git a/man/geom_node_text.Rd b/man/geom_node_text.Rd index 2a127b99..0d474eb4 100644 --- a/man/geom_node_text.Rd +++ b/man/geom_node_text.Rd @@ -28,7 +28,7 @@ displayed as described in ?plotmath} Useful for offsetting text from points, particularly on discrete scales.} \item{check_overlap}{If \code{TRUE}, text that overlaps previous text in the -same layer will not be plotted. A quick and dirty way} +same layer will not be plotted. Ignored if repel = TRUE. A quick and dirty way.} \item{show.legend}{logical. Should this layer be included in the legends? \code{NA}, the default, includes if any aesthetics are mapped. \code{FALSE} From 48b38a2d3c9a7c120d4835337eec068ae1bf5fbc Mon Sep 17 00:00:00 2001 From: Carson Sievert Date: Tue, 7 Feb 2017 17:43:14 -0600 Subject: [PATCH 2/2] fix install error --- DESCRIPTION | 1 + NAMESPACE | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 578f69b0..e64de454 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -63,6 +63,7 @@ Collate: 'layout_dendrogram.R' 'layout_igraph.R' 'layout_sec.R' + 'plotly.R' 'scale_edge_alpha.R' 'scale_edge_colour.R' 'scale_edge_fill.R' diff --git a/NAMESPACE b/NAMESPACE index 06fedd3e..71a5afa3 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -6,12 +6,6 @@ S3method(createLayout,dendrogram) S3method(createLayout,hclust) S3method(createLayout,igraph) S3method(createLayout,network) -S3method(to_basic,GeomEdgeBezier) -S3method(to_basic,GeomEdgeBspline) -S3method(to_basic,GeomEdgeDensity) -S3method(to_basic,GeomEdgePath) -S3method(to_basic,GeomEdgeSegment) -S3method(to_basic,GeomTreemap) S3method(treeApply,default) S3method(treeApply,dendrogram) S3method(treeApply,igraph) @@ -158,6 +152,12 @@ export(scale_edge_width_continuous) export(scale_edge_width_discrete) export(scale_edge_width_identity) export(scale_edge_width_manual) +export(to_basic.GeomEdgeBezier) +export(to_basic.GeomEdgeBspline) +export(to_basic.GeomEdgeDensity) +export(to_basic.GeomEdgePath) +export(to_basic.GeomEdgeSegment) +export(to_basic.GeomTreemap) export(treeApply) import(ggplot2) importFrom(MASS,bandwidth.nrd)