gradiant.color.range: generate desired color gradient

Description Usage Arguments Value Examples

Description

Used to generate desired color gradiants in ggplot. This is intended to be used with scale_fill_gradientn function. Find colors codes at: http://htmlcolorcodes.com/

Usage

1
gradiant.color.range(value, colors, cbreaks, tol = 0.05, report = FALSE)

Arguments

value

the numeric vector passed in ggplot that the user wishes to map to a gradient scale

colors

character string vector of hexidecimal color codes wished to use. Colors will be assigned from least to greatest of the value vector

cbreaks

vector equal length of colors, indicates at what value the user desires the color of that index to be.

tol

numeric of the level of tolerance of how close the colors will be to assigned cbreaks. Smaller tolerance will return a larger parsing. default set to 0.05 Adjustments may be necessary depending on the scale of value vector.

report

logical vector used to control if value estimates should be reported. Default set to FALSE. This function should not be used with scale_fill_gradientn if this param is set to TRUE.

Value

character string vector of hexidecimal codes of arbitrary length. This will be understood by scale_fill_gradientn functions 'colours' parameter.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
 df <- as.data.frame(cbind(rnorm(n = 100,mean = 0,sd = 20),
                           rep(c("A","B"), each=50),
                           rep(1:50, 2)))
 colnames(df) <- c("value","f1","f2")
 df$value <-as.numeric(as.character(df$value))
 df$f1 <- as.factor(df$f1)
 df$f2 <- as.factor(df$f2)
 ggplot(df, aes(x=f1,y=f2)) +
   geom_tile(aes(fill=value)) +
   scale_fill_gradientn(colours = gradiant.color.range(value = df$value,
                                                       colors = c("#A700FB",
                                                                  "#1700FB",
                                                                  "#14F3ED",
                                                                  "#FFFFFF",
                                                                  "#E0DD23",
                                                                  "#E09623",
                                                                  "#E03123"),
                                                       cbreaks = c(-40, -20,-10,0,10,20,40)),
                        breaks= c(-40, -20,-10,0,10,20,40))

jtlandis/justinmisc documentation built on May 25, 2019, 8:18 a.m.