Skip to content

Commit defd391

Browse files
committed
update documentations
data.R ggplot2_methods.R methods.R plotly_methods.R print_method.R
1 parent 5e9bb5f commit defd391

File tree

16 files changed

+471
-600
lines changed

16 files changed

+471
-600
lines changed

NAMESPACE

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,11 @@ S3method(unnest,tidySummarizedExperiment_nested)
3939
export("%>%")
4040
export(as_tibble)
4141
export(extract)
42-
export(ggplot)
4342
export(nest)
4443
export(pivot_longer)
4544
export(pivot_wider)
4645
export(plot_ly)
4746
export(separate)
48-
export(tbl_format_header)
4947
export(tidy)
5048
export(unite)
5149
export(unnest)
@@ -64,8 +62,6 @@ importFrom(SummarizedExperiment,colData)
6462
importFrom(SummarizedExperiment,rbind)
6563
importFrom(SummarizedExperiment,rowData)
6664
importFrom(SummarizedExperiment,rowRanges)
67-
importFrom(cli,cat_line)
68-
importFrom(cli,symbol)
6965
importFrom(dplyr,count)
7066
importFrom(dplyr,distinct)
7167
importFrom(dplyr,distinct_at)
@@ -128,7 +124,6 @@ importFrom(rlang,names2)
128124
importFrom(rlang,quo_is_null)
129125
importFrom(rlang,quo_name)
130126
importFrom(rlang,quo_squash)
131-
importFrom(stats,setNames)
132127
importFrom(stringr,regex)
133128
importFrom(stringr,str_detect)
134129
importFrom(stringr,str_replace)

R/data.R

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
#' Read counts of RNA-seq samples of Pasilla knock-down by Brooks et al.
22
#'
3-
#' A SummarizedExperiment dataset containing the transcriptome information for Drosophila Melanogaster.
3+
#' A SummarizedExperiment dataset containing
4+
#' the transcriptome information for Drosophila Melanogaster.
45
#'
56
#' @format containing 14599 features and 7 biological replicates.
67
#'
78
#' @source \url{https://bioconductor.org/packages/release/data/experiment/html/pasilla.html}
89
#' @usage data(pasilla)
910
"pasilla"
1011

11-
#' Read counts of RNA-seq samples derived from Pasilla knock-down by Brooks et al.
12+
#' Read counts of RNA-seq samples derived from
13+
#' Pasilla knock-down by Brooks et al.
1214
#'
13-
#' A SummarizedExperiment dataset containing the transcriptome information for Drosophila Melanogaster.
15+
#' A SummarizedExperiment dataset containing
16+
#' the transcriptome information for Drosophila Melanogaster.
1417
#'
1518
#' @format containing 14599 features and 7 biological replicates.
1619
#'

R/ggplot2_methods.R

Lines changed: 20 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,29 @@
1-
2-
#' Create a new ggplot from a tidySummarizedExperiment object
3-
#'
4-
#'
5-
#' `ggplot()` initializes a ggplot object. It can be used to
6-
#' declare the input data frame for a graphic and to specify the
7-
#' set of plot aesthetics intended to be common throughout all
8-
#' subsequent layers unless specifically overridden.
9-
#'
10-
#' `ggplot()` is used to construct the initial plot object,
11-
#' and is almost always followed by `+` to add component to the
12-
#' plot. There are three common ways to invoke `ggplot()`:
13-
#'
14-
#'
15-
#' The first method is recommended if all layers use the same
16-
#' data and the same set of aesthetics, although this method
17-
#' can also be used to add a layer using data from another
18-
#' data frame. See the first example below. The second
19-
#' method specifies the default data frame to use for the plot,
20-
#' but no aesthetics are defined up front. This is useful when
21-
#' one data frame is used predominantly as layers are added,
22-
#' but the aesthetics may vary from one layer to another. The
23-
#' third method initializes a skeleton `ggplot` object which
24-
#' is fleshed out as layers are added. This method is useful when
25-
#' multiple data frames are used to produce different layers, as
26-
#' is often the case in complex graphics.
27-
#'
28-
#' @importFrom ggplot2 aes
29-
#' @importFrom ggplot2 ggplot
30-
#'
31-
#' @param .data Default dataset to use for plot. If not already a data.frame,
32-
#' will be converted to one by [fortify()]. If not specified,
33-
#' must be supplied in each layer added to the plot.
34-
#' @param mapping Default list of aesthetic mappings to use for plot.
35-
#' If not specified, must be supplied in each layer added to the plot.
36-
#' @param ... Other arguments passed on to methods. Not currently used.
37-
#' @param environment DEPRECATED. Used prior to tidy evaluation.
38-
#'
39-
#' @return A ggplot
40-
#'
41-
#' @export
42-
#'
43-
#' @rdname ggplot2-methods
441
#' @name ggplot
2+
#' @rdname ggplot
3+
#' @inherit ggplot2::ggplot
4+
#' @title Create a new \code{ggplot} from a \code{tidyseurat}
5+
#' @return `ggplot`
456
#'
467
#' @examples
47-
#'
488
#' library(ggplot2)
49-
#'
50-
#' tidySummarizedExperiment::pasilla %>%
51-
#'
52-
#' tidySummarizedExperiment::ggplot(aes(sample, counts)) +
9+
#' data(pasilla)
10+
#' pasilla %>%
11+
#' ggplot(aes(.sample, counts)) +
5312
#' geom_boxplot()
54-
NULL
55-
13+
#'
14+
#' @importFrom purrr map
15+
#' @importFrom rlang quo_name
16+
#' @importFrom ggplot2 aes ggplot
5617
#' @export
57-
ggplot.SummarizedExperiment <- function(data=NULL, mapping=aes(), ..., environment=parent.frame()) {
58-
59-
# Deprecation of special column names
60-
if(is_sample_feature_deprecated_used(
61-
data,
62-
mapping %>% unlist() %>% map(~ quo_name(.x)) %>% unlist() %>% as.character()
63-
)){
64-
data= ping_old_special_column_into_metadata(data)
65-
}
18+
ggplot.SummarizedExperiment <- function(data=NULL, mapping=aes(),
19+
..., environment=parent.frame()) {
20+
21+
# Deprecation of special column names
22+
.cols <- enquos(..., .ignore_empty="all") %>%
23+
map(~ quo_name(.x)) %>% unlist()
24+
if (is_sample_feature_deprecated_used(data, .cols)) {
25+
data <- ping_old_special_column_into_metadata(data)
26+
}
6627

6728
data %>%
6829
as_tibble() %>%

R/methods.R

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,40 @@
11
setMethod(
2-
f = "show",
3-
signature = "SummarizedExperiment",
4-
definition = function(object) {
5-
if (
6-
isTRUE(x = getOption(x = "restore_SummarizedExperiment_show", default = FALSE)) |
7-
8-
# If the object is a SingleCellExperiment
9-
# # From BioC 3_14 SingleCellExperiment is SummarizedExperiment and
10-
# # we don't want to process with tidySummarizedExperiment
11-
is(object, "SingleCellExperiment")
2+
f="show",
3+
signature="SummarizedExperiment",
4+
definition=function(object) {
5+
if (isTRUE(x=getOption(x="restore_SummarizedExperiment_show",
6+
default = FALSE)) |
7+
# If the object is a SingleCellExperiment
8+
# # From BioC 3_14 SingleCellExperiment is SummarizedExperiment and
9+
# # we don't want to process with tidySummarizedExperiment
10+
is(object, "SingleCellExperiment")
1211
) {
1312
f <- getMethod(
14-
f = "show",
15-
signature = "SummarizedExperiment",
16-
where = asNamespace(ns = "SummarizedExperiment")
13+
f="show",
14+
signature="SummarizedExperiment",
15+
where=asNamespace(ns="SummarizedExperiment")
1716
)
18-
f(object = object)
17+
f(object=object)
1918
} else {
2019
object %>%
2120
print()
2221
}
2322
}
2423
)
2524

26-
2725
setClass("tidySummarizedExperiment", contains=c("SummarizedExperiment", "RangedSummarizedExperiment"))
2826

29-
30-
#' tidy for SummarizedExperiment
31-
#'
32-
#' @param object A SummarizedExperiment object
33-
#'
34-
#' @return A tidySummarizedExperiment object
35-
#'
36-
#' @description
37-
#'
38-
#' DEPRECATED. Not needed any more.
39-
#'
4027
#' @name tidy
28+
#' @rdname tidy
29+
#' @title tidy for `Seurat`
30+
#'
31+
#' @param object A `Seurat` object.
32+
#' @return A `tidyseurat` object.
4133
#'
4234
#' @examples
35+
#' data(pasilla)
36+
#' pasilla %>% tidy()
4337
#'
44-
#' tidySummarizedExperiment::pasilla %>% tidy()
4538
#' @export
4639
tidy <- function(object) {
4740
UseMethod("tidy", object)

R/plotly_methods.R

Lines changed: 10 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -1,144 +1,13 @@
1-
#' Initiate a plotly visualization
2-
#'
3-
#' This function maps R objects to [plotly.js](https://plot.ly/javascript/),
4-
#' an (MIT licensed) web-based interactive charting library. It provides
5-
#' abstractions for doing common things (e.g. mapping data values to
6-
#' fill colors (via `color`) or creating [animation]s (via `frame`)) and sets
7-
#' some different defaults to make the interface feel more 'R-like'
8-
#' (i.e., closer to [plot()] and [ggplot2::qplot()]).
9-
#'
10-
#' @details Unless `type` is specified, this function just initiates a plotly
11-
#' object with 'global' attributes that are passed onto downstream uses of
12-
#' [add_trace()] (or similar). A [formula] must always be used when
13-
#' referencing column name(s) in `data` (e.g. `plot_ly(mtcars, x=~wt)`).
14-
#' Formulas are optional when supplying values directly, but they do
15-
#' help inform default axis/scale titles
16-
#' (e.g., `plot_ly(x=mtcars$wt)` vs `plot_ly(x=~mtcars$wt)`)
17-
#'
18-
#' @param data A data frame (optional) or [crosstalk::SharedData] object.
19-
#' @param ... Arguments (i.e., attributes) passed along to the trace `type`.
20-
#' See [schema()] for a list of acceptable attributes for a given trace `type`
21-
#' (by going to `traces` -> `type` -> `attributes`). Note that attributes
22-
#' provided at this level may override other arguments
23-
#' (e.g. `plot_ly(x=1:10, y=1:10, color=I("red"), marker=list(color="blue"))`).
24-
#' @param type A character string specifying the trace type
25-
#' (e.g. `"scatter"`, `"bar"`, `"box"`, etc).
26-
#' If specified, it *always* creates a trace, otherwise
27-
#' @param name Values mapped to the trace's name attribute. Since a trace can
28-
#' only have one name, this argument acts very much like `split` in that it
29-
#' creates one trace for every unique value.
30-
#' @param color Values mapped to relevant 'fill-color' attribute(s)
31-
#' (e.g. [fillcolor](https://plot.ly/r/reference#scatter-fillcolor),
32-
#' [marker.color](https://plot.ly/r/reference#scatter-marker-color),
33-
#' [textfont.color](https://plot.ly/r/reference/#scatter-textfont-color), etc.).
34-
#' The mapping from data values to color codes may be controlled using
35-
#' `colors` and `alpha`, or avoided altogether via [I()]
36-
#' (e.g., `color=I("red")`).
37-
#' Any color understood by [grDevices::col2rgb()] may be used in this way.
38-
#' @param colors Either a colorbrewer2.org palette name
39-
#' (e.g. "YlOrRd" or "Blues"),
40-
#' or a vector of colors to interpolate in hexadecimal "#RRGGBB" format,
41-
#' or a color interpolation function like `colorRamp()`.
42-
#' @param stroke Similar to `color`, but values are mapped to relevant 'stroke-color' attribute(s)
43-
#' (e.g., [marker.line.color](https://plot.ly/r/reference#scatter-marker-line-color)
44-
#' and [line.color](https://plot.ly/r/reference#scatter-line-color)
45-
#' for filled polygons). If not specified, `stroke` inherits from `color`.
46-
#' @param strokes Similar to `colors`, but controls the `stroke` mapping.
47-
#' @param alpha A number between 0 and 1 specifying the alpha channel applied to `color`.
48-
#' Defaults to 0.5 when mapping to [fillcolor](https://plot.ly/r/reference#scatter-fillcolor) and 1 otherwise.
49-
#' @param alpha_stroke Similar to `alpha`, but applied to `stroke`.
50-
#' @param symbol (Discrete) values mapped to [marker.symbol](https://plot.ly/r/reference#scatter-marker-symbol).
51-
#' The mapping from data values to symbols may be controlled using
52-
#' `symbols`, or avoided altogether via [I()] (e.g., `symbol=I("pentagon")`).
53-
#' Any [pch] value or [symbol name](https://plot.ly/r/reference#scatter-marker-symbol) may be used in this way.
54-
#' @param symbols A character vector of [pch] values or [symbol names](https://plot.ly/r/reference#scatter-marker-symbol).
55-
#' @param linetype (Discrete) values mapped to [line.dash](https://plot.ly/r/reference#scatter-line-dash).
56-
#' The mapping from data values to symbols may be controlled using
57-
#' `linetypes`, or avoided altogether via [I()] (e.g., `linetype=I("dash")`).
58-
#' Any `lty` (see [par]) value or [dash name](https://plot.ly/r/reference#scatter-line-dash) may be used in this way.
59-
#' @param linetypes A character vector of `lty` values or [dash names](https://plot.ly/r/reference#scatter-line-dash)
60-
#' @param size (Numeric) values mapped to relevant 'fill-size' attribute(s)
61-
#' (e.g., [marker.size](https://plot.ly/r/reference#scatter-marker-size),
62-
#' [textfont.size](https://plot.ly/r/reference#scatter-textfont-size),
63-
#' and [error_x.width](https://plot.ly/r/reference#scatter-error_x-width)).
64-
#' The mapping from data values to symbols may be controlled using
65-
#' `sizes`, or avoided altogether via [I()] (e.g., `size=I(30)`).
66-
#' @param sizes A numeric vector of length 2 used to scale `size` to pixels.
67-
#' @param span (Numeric) values mapped to relevant 'stroke-size' attribute(s)
68-
#' (e.g.,
69-
#' [marker.line.width](https://plot.ly/r/reference#scatter-marker-line-width),
70-
#' [line.width](https://plot.ly/r/reference#scatter-line-width) for filled polygons,
71-
#' and [error_x.thickness](https://plot.ly/r/reference#scatter-error_x-thickness))
72-
#' The mapping from data values to symbols may be controlled using
73-
#' `spans`, or avoided altogether via [I()] (e.g., `span=I(30)`).
74-
#' @param spans A numeric vector of length 2 used to scale `span` to pixels.
75-
#' @param split (Discrete) values used to create multiple traces (one trace per value).
76-
#' @param frame (Discrete) values used to create animation frames.
77-
#' @param width Width in pixels (optional, defaults to automatic sizing).
78-
#' @param height Height in pixels (optional, defaults to automatic sizing).
79-
#' @param source a character string of length 1. Match the value of this string
80-
#' with the source argument in [event_data()] to retrieve the
81-
#' event data corresponding to a specific plot (shiny apps can have multiple plots).
82-
#' @author Carson Sievert
83-
#' @references <https://plotly-r.com/overview.html>
84-
#' @seealso \itemize{
85-
#' \item For initializing a plotly-geo object: [plot_geo()]
86-
#' \item For initializing a plotly-mapbox object: [plot_mapbox()]
87-
#' \item For translating a ggplot2 object to a plotly object: [ggplotly()]
88-
#' \item For modifying any plotly object: [layout()], [add_trace()], [style()]
89-
#' \item For linked brushing: [highlight()]
90-
#' \item For arranging multiple plots: [subplot()], [crosstalk::bscols()]
91-
#' \item For inspecting plotly objects: [plotly_json()]
92-
#' \item For quick, accurate, and searchable plotly.js reference: [schema()]
93-
#' }
94-
#'
95-
#' @return A plotly
96-
#'
97-
#' @importFrom plotly plot_ly
98-
#'
99-
#' @export
100-
#' @examples
1+
#' @name plotly
2+
#' @rdname plotly
3+
#' @inherit plotly::plot_ly
4+
#' @return `plotly`
1015
#'
102-
#' # Plotly better not run
103-
#' print("See below examples")
6+
#' @examples
7+
#' # TODO
1048
#'
105-
#' \dontrun{
106-
#' # plot_ly() tries to create a sensible plot based on the information you
107-
#' # give it. If you don't provide a trace type, plot_ly() will infer one.
108-
#' plot_ly(economics, x=~pop)
109-
#' plot_ly(economics, x=~date, y=~pop)
110-
#' # plot_ly() doesn't require data frame(s), which allows one to take
111-
#' # advantage of trace type(s) designed specifically for numeric matrices
112-
#' plot_ly(z=~volcano)
113-
#' plot_ly(z=~volcano, type="surface")
114-
#'
115-
#' # plotly has a functional interface: every plotly function takes a plotly
116-
#' # object as it's first input argument and returns a modified plotly object
117-
#' add_lines(plot_ly(economics, x=~date, y=~ unemploy / pop))
118-
#'
119-
#' # To make code more readable, plotly imports the pipe operator from magrittr
120-
#' economics %>%
121-
#' plot_ly(x=~date, y=~ unemploy / pop) %>%
122-
#' add_lines()
123-
#'
124-
#' # Attributes defined via plot_ly() set 'global' attributes that
125-
#' # are carried onto subsequent traces, but those may be over-written
126-
#' plot_ly(economics, x=~date, color=I("black")) %>%
127-
#' add_lines(y=~uempmed) %>%
128-
#' add_lines(y=~psavert, color=I("red"))
129-
#'
130-
#' # Attributes are documented in the figure reference -> https://plot.ly/r/reference
131-
#' # You might notice plot_ly() has named arguments that aren't in this figure
132-
#' # reference. These arguments make it easier to map abstract data values to
133-
#' # visual attributes.
134-
#' p <- plot_ly(iris, x=~Sepal.Width, y=~Sepal.Length)
135-
#' add_markers(p, color=~Petal.Length, size=~Petal.Length)
136-
#' add_markers(p, color=~Species)
137-
#' add_markers(p, color=~Species, colors="Set1")
138-
#' add_markers(p, symbol=~Species)
139-
#' add_paths(p, linetype=~Species)
140-
#' }
141-
#'
9+
#' @importFrom plotly plot_ly
10+
#' @export
14211
plot_ly <- function(data=data.frame(), ..., type=NULL, name=NULL,
14312
color=NULL, colors=NULL, alpha=NULL,
14413
stroke=NULL, strokes=NULL, alpha_stroke=1,
@@ -151,8 +20,8 @@ plot_ly <- function(data=data.frame(), ..., type=NULL, name=NULL,
15120
UseMethod("plot_ly")
15221
}
15322

23+
#' @rdname plotly
15424
#' @export
155-
#'
15625
plot_ly.tbl_df <- function(data=data.frame(), ..., type=NULL, name=NULL,
15726
color=NULL, colors=NULL, alpha=NULL,
15827
stroke=NULL, strokes=NULL, alpha_stroke=1,
@@ -179,6 +48,7 @@ plot_ly.tbl_df <- function(data=data.frame(), ..., type=NULL, name=NULL,
17948
)
18049
}
18150

51+
#' @rdname plotly
18252
#' @export
18353
plot_ly.SummarizedExperiment <- function(data=data.frame(), ..., type=NULL, name=NULL,
18454
color=NULL, colors=NULL, alpha=NULL,

0 commit comments

Comments
 (0)