tab1 | R Documentation |
One-way tabulation with automatic bar chart and optional indicator variables generation
tab1(x0, decimal = 1, sort.group = FALSE, cum.percent = !any(is.na(x0)), graph = TRUE, missing = TRUE, bar.values = "frequency", horiz = FALSE, cex = 1, cex.names = 1, main = "auto", xlab = "auto", ylab = "auto", col = "auto", gen.ind.vars = FALSE, ...) ## S3 method for class 'tab1' print(x, ...)
x0 |
a variable |
decimal |
number of decimals for the percentages in the table |
sort.group |
pattern for sorting categories in the table and in the chart. Default is no sorting. I can also be "decreasing" or "increasing". |
cum.percent |
presence of cumulative percentage in the output table. Default is TRUE for a variable without any missing values. |
graph |
whether a graph should be shown |
missing |
include the missing values category or <NA> in the graphic display |
bar.values |
include the value of frequency. This can also be "percent" or "none" at the end of each bar |
horiz |
set the bar chart to horizontal orientation |
cex |
parameter for extension of characters or relative size of the bar.values |
cex.names |
character extension or relative scale of the name labels for the bars |
main |
main title of the graph |
xlab |
label of X axis |
ylab |
label of Y axis |
col |
colours of the bar |
gen.ind.vars |
whether the indicator variables will be generated |
x |
object of class 'tab1' obtained from saving 'tab1' results |
... |
further arguments passed to or used by other methods |
'tab1' is an advanced one-way tabulation providing a nice frequency table as well as a bar chart. The description of the variable is also used in the main title of the graph.
The bar chart is vertical unless the number of categories is more than six and any of the labels of the levels consists of more than 8 characters or 'horiz' is set to TRUE.
For table has less than categories, the automatic colour is "grey". Otherwise, the graph will be colourful. The argument, 'col' can be overwritten by the user.
The argument 'gen.ind.vars' is effective only if x0 is factor.
Output table
Virasakdi Chongsuvivatwong cvirasak@gmail.com
'tabpct', 'label.var', 'table', 'barplot', 'model.matrix'
tab1(state.division) tab1(state.division, bar.values ="percent") tab1(state.division, sort.group ="decreasing") tab1(state.division, sort.group ="increasing") tab1(state.division, col=c("chocolate","brown1","brown4"), main="Number of states in each zone") # For presentation, several 'cex' parameters should increase tab1(state.division, col=c("chocolate","brown1","brown4"), main="Number of states in each zone", cex.main=1.7, cex.name=1.2, cex.axis=1.3, cex.lab=1.3) data(Oswego) .data <- Oswego attach(.data) tab1(ill) # Note the column of cumulative percentages in the table. tab1(ill, cum.percent=FALSE) tab1(chocolate) # Due to missing values, cumulative percentages are now automatically turned off. tab1(chocolate, cum.percent=TRUE) # Slightly too many columns in text! tab1(chocolate, missing=FALSE, bar.values="percent") agegr <- cut(age, breaks=c(0,10,20,30,40,50,60,70,80)) tab1(agegr) # No need to start with 'calc' as it is outside .data tab1(agegr, col="grey") # graphic output from older versions of 'tab1' tab1(agegr, col=c("red","yellow","blue")) # Colours recycled tab1(agegr, horiz=TRUE) # Keeping output table dev.off() tab1(agegr, graph = FALSE) -> a print(a) a # same results attributes(a) a$output.table class(a$output.table) # "matrix" # 'a$output.table' is ready for exporting to a .csv file by # write.csv(a$output.table, file="table1.csv") # "table1.csv" is now readable by a spreadsheet program detach(.data) rm(list=ls())
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.