geom_braid | R Documentation |
Summarize and plot measurements of two inputs as a discrete raster or "stained-glass" plot
geom_braid(
mapping = NULL,
data = NULL,
stat = "braid",
position = "identity",
...,
space = 1.5,
trim = TRUE,
shared = FALSE,
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE
)
stat_braid(
mapping = NULL,
data = NULL,
geom = "tile",
position = "identity",
...,
space = 1.5,
trim = TRUE,
shared = FALSE,
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE
)
geom_braid_glass(
mapping = NULL,
data = NULL,
stat = "braid_glass",
position = "identity",
...,
space = 1.5,
trim = TRUE,
shared = FALSE,
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE
)
stat_braid_glass(
mapping = NULL,
data = NULL,
geom = "polygon",
position = "identity",
...,
space = 1.5,
trim = TRUE,
shared = FALSE,
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE
)
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
The statistical transformation to use on the data for this layer.
When using a
|
position |
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The
|
... |
Additional parameters to be passed to |
space |
Parameter specifying the separation between marginal tiles and the main grid. Describes the distance from the center of the marginal tile to the center of the nearest main grid tile, divided by the width or height of the tile. If a single value is provided, it is used for both left-right and top-bottom margin tiles. If two values are provided, the first is used for left-right margin tiles and the second is used for top-bottom margin tiles. |
trim |
Should values that are finite in one dimension be dropped if their finite coordinates lie outside the bounds of the main grid? |
shared |
Should marginal offsets and trimming be calculated separately
for each facet if plots are faceted. If |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
geom |
The geometric object to use to display the data for this layer.
When using a
|
While the existing ggplot2
package includes several functions that are
extremely effective and versatile for visualizing two-dimensional responses,
including ggplot2::geom_raster()
, ggplot2::geom_tile()
, and
ggplot2::geom_contour()
, a number of considerations particular to combination
data make these functions, as is, somewhat difficult to use. First, these
functions are not designed for data in which pairs of x- and y-coordinates
are duplicated; yet this is very common in experimental data. While such
duplications can be handled prior to calling a visualization function,
handling them automatically reduces the barrier to plotting.
A second, and much more challenging consideration, is that for many drug
combination studies, drug concentrations are measured as a series of equal
ratio dilutions; visualizing such doses is most intuitive on a logarithmic
scale. But when inputs are scaled logarithmically, zeros become infinite
and are automatically removed by nearly all ggplot2
functions. This makes
it very difficult to plot measurements of drugs in isolation and in
combination in the same plot. geom_braid
addresses this by automatically
offsetting any measurements whose transformed coordinates are infinite to
margins within the plotted space, so that all values can be plotted together.
While geom_braid
is suitable for most response surfaces, some surfaces
feature measurements that are not arranged in a evenly spaced checkerboard.
For such surfaces, geom_braid_glass
produces a set of Voronoi polygons
centered on the available transformed coordinates, creating what we call a
"stained glass" plot. Marginal points are still represented by rectangles,
but with width and height such that boundaries are equidistant between
adjacent points.
stat_braid
and stat_braid_glass
are simply the corresponding stat_
functions for these two functions.
concentrations <- c(0,2^(-3:3))
surface <- data.frame(
concA = rep(rep(concentrations,each=length(concentrations)),each=3),
concB = rep(rep(concentrations,times=length(concentrations)),each=3),
replicate = rep(c(1,2,3),times=(length(concentrations)^2))
)
surface$actual <- evalBraidModel(
surface$concA,
surface$concB,
c(1, 1, 3, 3, 2, 0, 100, 100, 100)
)
surface$measure <- surface$actual + rnorm(nrow(surface),sd=7)
ggplot(surface,aes(x=concA,y=concB))+
geom_braid(aes(fill=measure))+
scale_x_log10()+
scale_y_log10()+
scale_fill_distiller(palette="RdYlBu")+
coord_equal()+
labs(x="Drug A",y="Drug B",fill="Effect")
glassSurface <- surface
glassSurface$concA[glassSurface$replicate==2] <-
glassSurface$concA[glassSurface$replicate==2]*1.25
glassSurface$concB[glassSurface$replicate==3] <-
glassSurface$concB[glassSurface$replicate==3]*1.25
glassSurface$actual <- evalBraidModel(
glassSurface$concA,
glassSurface$concB,
c(1, 1, 3, 3, -0.5, 0, 60, 100, 100)
)
glassSurface$measure <- glassSurface$actual+rnorm(nrow(glassSurface),sd=7)
ggplot(glassSurface,aes(x=concA,y=concB))+
geom_braid_glass(aes(fill=measure))+
scale_x_log10("Drug A")+
scale_y_log10("Drug B")+
scale_fill_distiller("Effect",palette="RdYlBu")+
coord_equal()
glassSurface$tilewidth <- log10(2)*0.9
glassSurface$tilewidth[glassSurface$concA==0] <- log10(2)/2
glassSurface$tileheight <- log10(2)*0.9
glassSurface$tileheight[glassSurface$concB==0] <- log10(2)/2
ggplot(glassSurface,aes(x=concA,y=concB))+
geom_braid_glass(aes(fill=measure,width=tilewidth,height=tileheight),space=2)+
scale_x_log10("Drug A")+
scale_y_log10("Drug B")+
scale_fill_distiller("Effect",palette="RdYlBu")+
coord_equal()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.