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 |
data |
Dataset used in this layer. |
... |
Optional arguments. |
Details
This function draws a stick figure.
The following aesthetics are required:
x: x position of the center of the head.
y: y position of the center of the head.
scale: scale of the man. It is the size of the man (in units of the Y axis).
ratioxy: Ratio x to y of the graph (Use ratioxy <- diff(xrange) / diff(yrange))
angleofspine: angle between the spine and a horizontal line that passes by the center of the head.
anglerighthumerus, anglelefthumerus: angle between the right/left humerus and a horizontal line that passes by the top of the spine.
anglerightradius, angleleftradius: angle between the right/left radius and a horizontal line that passes by the end of the right/left humerus.
anglerightleg, anglelefthleg: angle between the right/left left and a horizontal line that passes by the end of the end of the spine.
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
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)