xkcdman {xkcd}R Documentation

Draw a stick figure

Description

It draws a stick figure

Usage

xkcdman(mapping, data, ...)

Arguments

mapping

Mapping between variables and aesthetics generated by aes. See Details.

data

Dataset used in this layer.

...

Optional arguments.

Details

This function draws a stick figure.

The following aesthetics are required:

  1. x: x position of the center of the head.

  2. y: y position of the center of the head.

  3. scale: scale of the man. It is the size of the man (in units of the Y axis).

  4. ratioxy: Ratio x to y of the graph (Use ratioxy <- diff(xrange) / diff(yrange))

  5. angleofspine: angle between the spine and a horizontal line that passes by the center of the head.

  6. anglerighthumerus, anglelefthumerus: angle between the right/left humerus and a horizontal line that passes by the top of the spine.

  7. anglerightradius, angleleftradius: angle between the right/left radius and a horizontal line that passes by the end of the right/left humerus.

  8. anglerightleg, anglelefthleg: angle between the right/left left and a horizontal line that passes by the end of the end of the spine.

  9. angleofneck: angle between the begin of spine and a horizontal line that passes by the center of the head.

Angles are in radians.

Additionally, you can use the aesthetics of geom_path, and xkcdline.

Value

A layer.

See Also

aes, geom_path, xkcdline

Examples

datascaled <- data.frame(x=c(-3,3),y=c(-30,30))
p <- ggplot(data=datascaled, aes(x=x,y=y)) + geom_point()
xrange <- range(datascaled$x)
yrange <- range(datascaled$y)
ratioxy <- diff(xrange) / diff(yrange)
 
mapping <- aes(x=x,
               y=y,
               scale=scale,
               ratioxy=ratioxy,
               angleofspine = angleofspine,
               anglerighthumerus = anglerighthumerus,
               anglelefthumerus = anglelefthumerus,
               anglerightradius = anglerightradius,
               angleleftradius = angleleftradius,
               anglerightleg =  anglerightleg,
               angleleftleg = angleleftleg,
               angleofneck = angleofneck,
               color = color )
 
dataman <- data.frame( x= c(-1,0,1), y=c(-10,0,10),
                  scale = c(10,7,5),
                  ratioxy = ratioxy,
                  angleofspine =  seq(- pi / 2, -pi/2 + pi/8, l=3) ,
                  anglerighthumerus = -pi/6,
                  anglelefthumerus = pi + pi/6,
                  anglerightradius = 0,
                  angleleftradius = runif(3,- pi/4, pi/4),
                  angleleftleg = 3*pi/2  + pi / 12 ,
                  anglerightleg = 3*pi/2  - pi / 12,
                  angleofneck = runif(3, min = 3 * pi / 2 - pi/10 , max = 3 * pi / 2 + pi/10),
                  color=c("A","B","C"))
 
p + xkcdman(mapping,dataman)

[Package xkcd version 0.0.6 Index]