#
# 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 )
}
Run the code above in your browser using DataLab