Description Usage Arguments Value Examples
creates a FlexTable
by transposing variables into observations.
1 2 3 |
dataset |
a tidy data.frame. |
id |
variable whose values are used to identify transposed variables |
transpose |
transpose each |
columns |
variables to transpose |
columns.transpose |
transpose also |
color |
optional, font color, named character vector, names are specifying
which element of |
background.color |
optional, cell background color, named character vector,
names are specifying which element of |
space.table |
add a space after each group |
column.label |
label for column name of stacked |
a FlexTable
object
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | #
# load ggplot2
if( require("dplyr", quietly = TRUE) ){
data = mtcars
data = group_by(data, vs, am, gear, carb)
data = summarise(data, avg = mean( mpg ), min = min( mpg ))
data$avg_col = ifelse( data$avg < 17, "red", "black" )
data$min_col = ifelse( data$min < 20, "gray", "purple" )
data$avg = sprintf( "%.3f", data$avg)
data$min = sprintf( "%.2f", data$min)
ft = FlexPivot( dataset = data, space = FALSE, columns.transpose = TRUE,
id = c("gear", "carb"), transpose = c("vs", "am"),
columns = c("avg", "min"),
color = c("avg"="avg_col", "min" = "min_col") )
print( ft )
if( interactive() ) readline("Hit <Return> to see next FlexTable:")
ft = FlexPivot( dataset = data, space = TRUE, columns.transpose = TRUE,
id = c("gear", "carb"), transpose = c("vs", "am"),
columns = c("avg", "min") )
print( ft )
if( interactive() ) readline("Hit <Return> to see next FlexTable:")
ft = FlexPivot( dataset = data, space = FALSE, columns.transpose = FALSE,
id = c("gear", "carb"), transpose = c("vs", "am"),
columns = c("avg", "min") )
print( ft )
if( interactive() ) readline("Hit <Return> to see next FlexTable:")
ft = FlexPivot( dataset = data, space = TRUE,
columns.transpose = FALSE,
id = c("gear", "carb"),
transpose = c("vs", "am"),
columns = c("avg", "min")
)
print( ft )
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.