show.digit: Show a MNIST digit

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/show.digit.R

Description

Plots an image representing the supplied MNIST digit

Usage

1
show.digit(digit, col=gray(12:1/12), ...)

Arguments

digit

a digit from the mnist dataset.

col

a vector of colors to represent the digit. See image for more details.

...

further arguments passed to image.

Details

This function uses the image graphics function to represent a digit in a plot window.

Value

None

Author(s)

Xavier Robin

References

Freely inspired from https://gist.github.com/brendano/39760

See Also

mnist

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
data(mnist)

show.digit(mnist$test$x[1,])
show.digit(mnist$train$x[1,])

good.digits <- c(11, 3, 2, 91, 20, 188, 92, 1, 111, 13)
rainbow <- c("#FF0000FF", "#0000FFFF", "#964B00FF", "#FF00FFFF", "#00AAAAFF", "#00EE00FF", "#FFFFFFFF", "#000000FF", "#AAAAAAFF", "#FF9900FF")
alphas.gen <- expand.grid(c(0:9, LETTERS[1:6]), c(0:9, LETTERS[1:6]))
alphas <- paste(alphas.gen[,2], alphas.gen[,1], sep="")
circle.borders <- rep("black", 10)
circle.borders[c(2, 8)] <- "white"

layout(matrix(1:16, 4, 4))
par(cex=1.5)
sapply(1:10, function(i) {show.digit(mnist$test$x[good.digits[i],], col=paste(substring(rainbow[ifelse(i == 7, 8, i)], 1, 7), if (i ==7) rev(alphas) else alphas, sep=""))})

xrobin/mnist documentation built on Dec. 14, 2020, 11:28 a.m.