pal2table: Color Palette to Table

View source: R/pal2table.r

pal2tableR Documentation

Color Palette to Table

Description

Creates a data frame assigning colors and symbols to factors

Usage

pal2table(x, pch = 21:24, pch2 = c(19, 15, 18, 17), alpha = 220, pal = "bro2")

Arguments

x

A vector of factors

pch

A list of symbols to be used

pch2

a second list of symbols

alpha

The transparency value for the color

pal

A vector of colors. Default is built-in color palette

Details

Aim of the the functions pal2table and match2table is to provide an easy framework for assigning same colors and symbols for same factors in different plots. Matching colors and symbols to factors is complicated when different graphs do not have the same factors in same order. pal2table will create a data frame assigning colors and symbols to factors. An object of type pal2table is created that will be interpreted by match2table. The later function can be used to create a vector of colors and symbols to be used by plot graphical parameters col, bg, fg, or pch. The function will assign the colors and symbols matching the name of factors in the data frame to the provided vector of names. pal2table has a plot method which will plot the assigned colors and symbols together with the names of the factors. The built-in color palette 'bro2' is modified from 'brocolors' from package 'broman' by Karl W Broman. It accepts changing the alpha value using the argument alpha. Using a different color palette with argument pal will probably inabilitate the alpha modulation. Please adjust alpha in your palette forehand. A second color palette 'c25' is modified from Kevin Wright https://stackoverflow.com/questions/9563711/r-color-palettes-for-many-data-classes. Note that you need to coerce col column to a vector if you want to use it directly from the pal2table object. See the legend example with iris below.

Value

An object of class pal2table. Dataframe with following columns.

class

names of the factors

col

assigned color

pch

assigned symbol

pch2

assigned second symbol

Author(s)

Pedro Martinez Arbizu

See Also

match2table

Examples

data(iris)
irc <- pal2table(iris$Species)
plot(irc)

#example with iris data
col <- match2table(iris$Species,irc,'col')
pch <- match2table(iris$Species,irc,'pch')
pch2 <- match2table(iris$Species,irc,'pch2')

#add space below graph
par(oma = c(2, 0, 0, 0),xpd=NA)
plot(iris[,1],iris[,3],pch=pch,bg=col,cex=2,xlab='Sepal length',ylab='Petal length')
legend(min(iris[,1]), min(iris[,3])-2,bty='n',ncol=3, pt.cex=1.5, legend=irc$class,pch=irc$pch2, col=as.vector(irc$col))
legend(min(iris[,1]), min(iris[,3])-2,bty='n',ncol=3, pt.cex=1.5, legend=irc$class,pch=irc$pch)

#example with barplot
barplot(as.matrix(iris[,-c(5)]),col=col,border=NA)


pmartinezarbizu/dada2pp documentation built on Feb. 7, 2024, 7:01 a.m.