scale_color_image {RImagePalette} | R Documentation |
Image color scales
Description
Uses the image color scale.
Usage
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 |
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 |
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 |
volume |
Logical volume controls the method for choosing which color cube to split
at each iteration of the algorithm. The default choice (when |
discrete |
generate a discrete palette? (default: |
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
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()