df_color2: Appends a column named "color" to a data frame containing hex...

Description Usage Arguments Value Examples

Description

Appends a column named "color" to a data frame containing hex codes (ready for usage in a plot) The values are determined by mixing two gradients that depend on two columns specified by the user.Therefore, the output is able to represent the value of two columns together. With "rgb" method, simultaneous low values for both columns return darker colors. With "hsv" method and "value" as second_parameter, darker points represent low values for the second variable. The first variable is represented by a blue-green-red gradient With "hsv" method and "saturation" as second_parameter, attenuated colors represent low values for the second variable. The first variable is represented by a blue-green-red gradient

Usage

1
2
3
df_color2(df, column1, column2, output_name = "color",
  max_color1 = "red", max_color2 = "green", method = "rgb",
  second_param = "saturation", min_saturation = 0.2, min_value = 0.4)

Arguments

df

Data frame containing the original data.

column1

A string containing the name of the column that will determine color's first gradient.

column2

A string containing the name of the column that will determine color's second gradient.

output_name

Name for the column in which the output will be stored. Defaults to "color"

max_color1

In case "rgb" method is used, color to be assigned to the row with the highest value in column1. Defaults to red

max_color2

In case "rgb" method is used, color to be assigned to the row with the highest value in column2. Defaults to green.

method

Type of gradient. Allows both "rgb" and "hsv". Defaults to "rgb"

second_param

In case "hsv" method is used, choose between "saturation" and "value" to be used as second parameter.

min_saturation

In case "hsv" method is used, sets minimum allowed value for "saturation". Data points with too low saturation may not appear visible. Defaults to 0.2

min_value

In case "hsv" method is used, sets minimum allowed value for "value". Data points with too low values may appear black regardless of the "hue" parameter. Defaults to 0.4

Value

A data frame identical to df, except for an extra column (whose name is given by output_name) containing hexcodes.

Examples

1
2
3
4
plot(mtcars$hp, mtcars$disp, col=df_color2(mtcars, "drat", "wt",method="rgb")$color, pch=18, cex=1.5)
plot(mtcars$hp, mtcars$disp, col=df_color2(mtcars, "drat", "wt",method="rgb", max_color1="green", max_color2="blue")$color, pch=18, cex=1.5)
plot(mtcars$hp, mtcars$disp, col=df_color2(mtcars, "drat", "wt", second_param = "saturation", method="hsv")$color, pch=18, cex=1.5)
plot(mtcars$hp, mtcars$disp, col=df_color2(mtcars, "drat", "wt", second_param ="value", method="hsv")$color, pch=18, cex=1.5)

dpcarballo/coloR documentation built on June 1, 2019, 8:14 p.m.