Learn R Programming

lemon (version 0.4.5)

geom_siderange: Display range of data in side of plot

Description

Projects data onto horizontal or vertical edge of panels.

Usage

geom_siderange(
  mapping = NULL,
  data = NULL,
  stat = "identity",
  position = "identity",
  ...,
  distance = 3,
  arrow = NULL,
  lineend = "butt",
  sides = "bl",
  start = NA,
  end = NA,
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = TRUE
)

Arguments

mapping

Set of aesthetic mappings created by aes or aes_.

data

The data to be displayed in this layer.

stat

The statistical transformation to use on the data for this layer, as a string.

position

Position adjustment, either as a string, or the result of a call to a position adjustment function (e.g. position_jitter). Both lines and points gets the same adjustment (this is where the function excels over geom_point() + geom_line()).

...

other arguments passed on to layer.

distance

Distance between edge of panel and lines, and distance between lines, in multiples of line widths, see description.

arrow

Arrow specification, as created by arrow.

lineend

Line end style (round, butt, square).

sides

Character including top, right, bottom, and/or left, indicating which side to project data onto.

start, end

Adds a symbol to either end of the siderange. start corresponds to minimal value, end to maximal value.

na.rm

If FALSE (default), missing values are removed with a warning. If TRUE, missing values are silently removed.

show.legend

Logical. Should this layer be included in the legends? NA (default), includes if any aesthetics are mapped. FALSE never includes, and TRUE always includes.

inherit.aes

If FALSE, overrides the default aesthetic, rather than combining with them. This is most useful for helper functions that define both data and aesthetics and shouldn't inherit behaviour from the default plot specification.

Aesthetics

The geom understands the following aesthetics (required are in bold):

  • x

  • y

  • alpha

  • colour

  • fill (if a symbol is applied with start or end

  • group

  • linetype

  • size

  • stroke

Details

The geom_siderange projects the data displayed in the panel onto the sides, using the same aesthetics. It has the added capability of potting a symbol at either end of the line, and lines are offset from the edge and each other.

To display a symbol, specify an integer for either start or end. See the list for pch in points for values to use. The argumetns start and end also accepts a list object with named entries pch, alpha, stroke, and fill, which correspond to the usual aesthetics, as well as a special named entry, sizer (note the extra 'r'). This last entry is a multiplier for enlarging the symbol relative to the linewidth, as the aesthetic size affects both linewidth and symbol size.

The distance between the panel's edge and sideranges are specified by the argument distance. If a symbol is specified, the linewidth is further expanded to cover the width of the symbol (including sizer).

See Also

Examples

Run this code
library(ggplot2)

x <- rnorm(25)
df <- data.frame(x=x, y=x+rnorm(25, sd=0.2), 
                 a=sample(c('horse','goat'), 25, replace=TRUE), 
                 stringsAsFactors = FALSE)
df$y <- with(df, ifelse(y > 1 & a=='horse', 1, y))
(p <- ggplot(df, aes(x=x, y=y, colour=a)) + geom_point(shape=1))

p + geom_siderange(start=19)

# Capping the sideranges with different symbols:
p + geom_siderange(start=19, end=22, fill='black', sides='b') + geom_siderange(sides='tl')

# It also works with facets

p <- ggplot(mpg, aes(displ, hwy, colour=fl)) +
  geom_point() +
  facet_wrap(~class, nrow = 4)

p + geom_siderange()

Run the code above in your browser using DataLab