xkcdman: Draw a stick figure

Description Usage Arguments Details Value See Also Examples

Description

It draws a stick figure

Usage

1
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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)

Example output

Loading required package: ggplot2
Loading required package: extrafont
Registering fonts with R

xkcd documentation built on May 2, 2019, 9:43 a.m.