Title: | Plotting ggplot2 Graphics in an XKCD Style |
---|---|
Description: | Plotting ggplot2 graphs using the XKCD style. |
Authors: | Emilio Torres-Manzanera |
Maintainer: | Emilio Torres-Manzanera <[email protected]> |
License: | GPL-3 |
Version: | 0.0.6 |
Built: | 2024-11-25 05:40:34 UTC |
Source: | https://github.com/cran/xkcd |
Plotting ggplot2 graphs using the XKCD style.
The DESCRIPTION file:
Package: | xkcd |
Type: | Package |
Title: | Plotting ggplot2 Graphics in an XKCD Style |
Version: | 0.0.6 |
Date: | 2018-07-10 |
Author: | Emilio Torres-Manzanera |
Maintainer: | Emilio Torres-Manzanera <[email protected]> |
Description: | Plotting ggplot2 graphs using the XKCD style. |
License: | GPL-3 |
Depends: | ggplot2 (>= 3.0), extrafont |
Imports: | Hmisc, stats |
URL: | |
NeedsCompilation: | no |
Packaged: | 2018-07-11 14:49:14 UTC; emilio |
RoxygenNote: | 6.0.1 |
Date/Publication: | 2018-07-11 15:30:02 UTC |
Config/pak/sysreqs: | make libicu-dev |
Repository: | https://emiliotorres.r-universe.dev |
RemoteUrl: | https://github.com/cran/xkcd |
RemoteRef: | HEAD |
RemoteSha: | 98ec2d3e24e8ad0ecc0f3d114be31939c44747f5 |
Index of help topics:
theme_xkcd Creates an XKCD theme xkcd-package Plotting ggplot2 Graphics in an XKCD Style xkcdaxis Plot the axis xkcdline Draw lines or circunferences xkcdman Draw a stick figure xkcdrect Draw fuzzy rectangles
Further information is available in the following vignettes:
xkcd-intro |
Using xkcd (source, pdf) |
Emilio Torres-Manzanera
Maintainer: Emilio Torres-Manzanera <[email protected]>
## Not run: vignette("xkcd-intro")
## Not run: vignette("xkcd-intro")
This function creates an XKCD theme
theme_xkcd()
theme_xkcd()
A layer with the theme.
See the vignette vignette("xkcd-intro")
## Not run: p <- ggplot() + geom_point(aes(mpg, wt), data=mtcars) + theme_xkcd() p ## End(Not run)
## Not run: p <- ggplot() + geom_point(aes(mpg, wt), data=mtcars) + theme_xkcd() p ## End(Not run)
This function plots the axis
xkcdaxis(xrange, yrange, ...)
xkcdaxis(xrange, yrange, ...)
xrange |
The range of the X axe. |
yrange |
The range of the Y axe. |
... |
Other arguments. |
It plots the axis of the graph.
A layer with the axis.
## Not run: xrange <- range(mtcars$mpg) yrange <- range(mtcars$wt) p <- ggplot() + geom_point(aes(mpg, wt), data=mtcars) + xkcdaxis(xrange,yrange) p ## End(Not run)
## Not run: xrange <- range(mtcars$mpg) yrange <- range(mtcars$wt) p <- ggplot() + geom_point(aes(mpg, wt), data=mtcars) + xkcdaxis(xrange,yrange) p ## End(Not run)
It draws a handwritten line.
xkcdline(mapping, data, typexkcdline = "segment", mask = TRUE, ...)
xkcdline(mapping, data, typexkcdline = "segment", mask = TRUE, ...)
mapping |
Mapping between variables and aesthetics generated by |
data |
Dataset used in this layer. |
typexkcdline |
A string value. If it is |
mask |
Logical. If it is TRUE, it erases the pictures that are under the line. |
... |
Optional arguments. |
This function draws handwritten lines or circles.
It draws a segment or a circunference in an XKCD style.
If it is a segment, the following aesthetics are required:
xbegin: x position of the point from.
ybegin: y position of the point from.
xend: x position of the point to.
yend: y position of the point to.
If it is a circunference, the following aesthetics are required:
x: x position of the center.
y: y position of the center.
diameter: diameter of the circunference.
Additionally, you can use the aesthetics of geom_path
.
A layer.
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(x=x1 +y1, y=y1, xend =xend, yend= yend, color = model), data=data) ggplot() + xkcdline(mapping=aes(x=x1 +y1, y=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")
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(x=x1 +y1, y=y1, xend =xend, yend= yend, color = model), data=data) ggplot() + xkcdline(mapping=aes(x=x1 +y1, y=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")
It draws a stick figure
xkcdman(mapping, data, ...)
xkcdman(mapping, data, ...)
mapping |
Mapping between variables and aesthetics generated by |
data |
Dataset used in this layer. |
... |
Optional arguments. |
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
.
A layer.
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)
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)
It draws fuzzy rectangles.
xkcdrect(mapping, data, ...)
xkcdrect(mapping, data, ...)
mapping |
Mapping between variables and aesthetics generated by |
data |
Dataset used in this layer. |
... |
Optional arguments. |
This function draws fuzzy rectangles.
It plots rectangles. The following aesthetics are required:
xmin
ymin
xmax
ymax
Additionally, you can use the aesthetics of geom_path
and geom_rect
.
A layer.
volunteers <- data.frame(year=c(2007:2011), number=c(56470, 56998,59686, 61783, 64251)) p <- ggplot() + xkcdrect(aes(xmin = year, xmax= year +0.3, ymin=number, ymax = number + 3600), volunteers, fill="red", colour="black") p
volunteers <- data.frame(year=c(2007:2011), number=c(56470, 56998,59686, 61783, 64251)) p <- ggplot() + xkcdrect(aes(xmin = year, xmax= year +0.3, ymin=number, ymax = number + 3600), volunteers, fill="red", colour="black") p