Learn R Programming

xkcd (version 0.0.3)

xkcdline: Draws handwritten lines

Description

This function draws ggplot2 segments or circles in a handwritten style.

Usage

xkcdline(mapping, data, typexkcdline = "segment", mask = TRUE, ...)

Arguments

mapping
Mapping between variables and aesthetics generated by aes. See Details.
data
Dataset used in this layer.
typexkcdline
A string value. If it is segment, it draws a segment. If it is circunference, it plots a circunference.
mask
Logical. If it is true, it erases the pictures that are under the line.
...
Optional arguments.

Value

  • A ggplot layer.

Details

It draws a segment or a circunference in a XKCD style. If it is a segment, the following aesthetics are required:
  1. xbegin: x position of the point from.
  2. ybegin: y position of the point from.
  3. xend: x position of the point to.
  4. yend: y position of the point to.

If it is a circunference, the following aesthetics are required:

  1. x: x position of the center.
  2. y: y position of the center.
  3. diameter: diameter of the circunference.
Additionally, you can use the aesthetics of geom_path, pointssegment and pointscircunference.

See Also

aes, geom_path, pointssegment, pointscircunference

Examples

Run this code
data <- data.frame(x1=c(1,2), y1=c(10,20), xend=c(2.5,0.5),
yend=c(20,10), model=c("low","high"))

ggplot() + xkcdline(mapping=aes(xbegin=x1 +y1, ybegin=y1, xend =xend, yend= yend,
color = model), data=data)

ggplot() + xkcdline(mapping=aes(xbegin=x1 +y1, ybegin=y1, xend =xend, yend= yend,
color = model), data=data) + facet_grid(. ~ model)

ggplot() + xkcdline(mapping=aes(x=x1 +y1, y=y1, diameter =xend), data=data, type="circunference")

Run the code above in your browser using DataLab