fortify_S4: Fortification of S4 vectors

Description Usage Arguments Details Value Note See Also Examples

Description

While the original fortify() function in ggplot2 was used to convert models and formulas to data.frames, it can also be used as a hook to customise data prior to being put through the plotting internals. Since ggplot exclusively handles data.frames, we use fortify methods to convert S4 vector objects to base data.frames.

Usage

1
2
3
4
5
## S3 method for class 'Vector'
fortify(model, data, ...)

## S3 method for class 'DataFrame'
fortify(model, data, ...)

Arguments

model

model or other R object to convert to data frame

data

original dataset, if needed

...

other arguments passed to methods

Details

The fortify methods in this package are written for two classes.

  1. The Vector virtual class from which a broad range of concrete classes in Bioconductor derive. The fortify method column-binds the Vector content itself to the the result of callling mcols() on the Vector and returns this as a base data.frame. The column containing the Vector content will be named .VectorClass, wherein VectorClass is the name of the input's class.

  2. The DataFrame class is converted to its base R equivalent. Beware that any element metadata from the Vectors in the DataFrame is not converted to seperate columns.

Value

A base R data.frame with (when applicable) S4 columns

Note

Although S4 vectors can be converted to base R data.frames, there is no guarantee that all functions tailored to data.frame will work. The rbind method for data.frame for example, implicitly converts columns to vectors. When there exists no such method for an S4 class, rbind will throw an error.

See Also

fortify for the original function in ggplot2.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# Element metadata of Vector classes are converted to columns
x <- Rle(1:5)
mcols(x) <- DataFrame(y = LETTERS[1:5])
fortify(x)

# Vector element metadata is not converted to a column when
# fortifying a DataFrame
df <- DataFrame(x = Rle(1:5), y = Factor(LETTERS[1:5]))
mcols(df$x) <- DataFrame(z = "I'm Vector metadata")
fortify(df)

teunbrand/ggnomics documentation built on Aug. 2, 2020, 7:34 p.m.