Package 'xkcd'

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

Help Index


Plotting ggplot2 Graphics in an XKCD Style

Description

Plotting ggplot2 graphs using the XKCD style.

Details

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)

Author(s)

Emilio Torres-Manzanera

Maintainer: Emilio Torres-Manzanera <[email protected]>

Examples

## Not run: vignette("xkcd-intro")

Creates an XKCD theme

Description

This function creates an XKCD theme

Usage

theme_xkcd()

Value

A layer with the theme.

Note

See the vignette vignette("xkcd-intro")

Examples

## Not run: 
p <- ggplot() + geom_point(aes(mpg, wt), data=mtcars) +
     theme_xkcd()
p

## End(Not run)

Plot the axis

Description

This function plots the axis

Usage

xkcdaxis(xrange, yrange, ...)

Arguments

xrange

The range of the X axe.

yrange

The range of the Y axe.

...

Other arguments.

Details

It plots the axis of the graph.

Value

A layer with the axis.

Examples

## 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)

Draw lines or circunferences

Description

It draws a handwritten line.

Usage

xkcdline(mapping, data, typexkcdline = "segment", mask = TRUE, ...)

Arguments

mapping

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

data

Dataset used in this layer.

typexkcdline

A string value. If it is segment, it draws a segment. If it is circunference, it plots a circunference.

mask

Logical. If it is TRUE, it erases the pictures that are under the line.

...

Optional arguments.

Details

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:

  1. xbegin: x position of the point from.

  2. ybegin: y position of the point from.

  3. xend: x position of the point to.

  4. yend: y position of the point to.

If it is a circunference, the following aesthetics are required:

  1. x: x position of the center.

  2. y: y position of the center.

  3. diameter: diameter of the circunference.

Additionally, you can use the aesthetics of geom_path.

Value

A layer.

See Also

aes, geom_path

Examples

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")

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)

Draw fuzzy rectangles

Description

It draws fuzzy rectangles.

Usage

xkcdrect(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 fuzzy rectangles.

It plots rectangles. The following aesthetics are required:

  1. xmin

  2. ymin

  3. xmax

  4. ymax

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

Value

A layer.

See Also

aes, geom_path

Examples

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