Description Usage Arguments Details Value Note See Also Examples
This function draws ggplot2 man in a handwritten style.
1 |
mapping |
Mapping between variables and aesthetics generated by aes. See Details. |
data |
Dataset used in this layer. |
... |
Optional arguments. |
It draws a man in a XKCD style. 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
.
A ggplot layer.
See vignette("xkcd-intro")
for a
graphical representation of the angles used in this function.
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.