scale_image: Image color scales

Description Usage Arguments Details See Also Examples

Description

Uses the image color scale.

Usage

1
2
3
4
5
6
7
8
scale_color_image(..., image, n = 3, choice = mean, volume = FALSE,
  discrete = TRUE)

scale_colour_image(..., image, n = 3, choice = mean, volume = FALSE,
  discrete = TRUE)

scale_fill_image(..., image, n = 3, choice = mean, volume = FALSE,
  discrete = TRUE)

Arguments

...

parameters to discrete_scale or scale_fill_gradientn

image

Matrix The image from which the palette will be extracted from. Should be a 3 (or more) dimensional matrix. The output of a function such as readJPG() or readPNG() are suitable as image.

n

For continuous color scales, you may optionally pass in an integer, n. This allows some control over the scale, if n is too large the scale has too many colors and ceases to be meaningul. n = 3 to n = 5 is recommended.

choice

Function Defines how the color will be chosen from the final color cubes. The default choice is to take the mean value of the image cube, but other choices may return a subjectively superior scale. Try median, or min, or max, or whatever summary statistic suits your fancy.

volume

Logical volume controls the method for choosing which color cube to split at each iteration of the algorithm. The default choice (when volume = FALSE) is to choose the cube which contains the largest extent (that is, the largest range of some color). When volume = TRUE, the cube with the largest volume is chosen to split. Occasionally, setting to TRUE returns a better palette.

discrete

generate a discrete palette? (default: FALSE - generate continuous palette)

Details

For discrete == TRUE (the default) the function will return a discrete_scale with the plot-computed number of colors. All other arguments are as to scale_fill_gradientn or scale_color_gradientn.

See image_palette for more information on the color scale.

See Also

median_cut image_palette vbox display_image

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
library(ggplot2)

# ripped from the pages of ggplot2
your_image <- jpeg::readJPEG(system.file("img", "Rlogo.jpg", package="jpeg"))
display_image(your_image)

#Discrete scale example
p <- ggplot(mtcars, aes(wt, mpg))
p + geom_point(size=4, aes(colour = factor(cyl))) +
    scale_color_image(image = your_image) +
    theme_bw()

#Continuous scale example
dsub <- subset(diamonds, x > 5 & x < 6 & y > 5 & y < 6)
dsub$diff <- with(dsub, sqrt(abs(x-y))* sign(x-y))
d <- ggplot(dsub, aes(x, y, colour=diff)) + geom_point()
d + scale_color_image(image = your_image, discrete=FALSE) + theme_bw()

joelcarlson/RImagePalette documentation built on Oct. 26, 2021, 3:34 a.m.