qplot_crosstab.Rd
Plot a crosstabulation (classification table)
qplot_crosstab(obj, ...)
# S3 method for table
qplot_crosstab(
tabl,
Title = "Cross-tabulation",
xLabel = NULL,
yLabel = NULL,
subTitle = NULL,
text.size = 5,
sort = FALSE,
bg.color = "skyblue1",
max.color = "gold3",
low.color = "grey80",
decimals = 1,
show.max = c("max", "colMax", "rowMax", FALSE),
shades = TRUE,
guide = c("legend", "colorbar", FALSE),
zero.color = "grey60",
text.color = "black",
as.percentage = c(FALSE, TRUE, "row", "col"),
...
)
# S3 method for numeric
qplot_crosstab(
varX,
varY,
Title = "Cross-tabulation",
xLabel = match.call()$varX,
yLabel = match.call()$varY,
...
)
# S3 method for hyperSpec
qplot_crosstab(
obj,
varX,
varY,
Title = "Cross-tabulation",
xLabel = NULL,
yLabel = NULL,
...
)
# S3 method for data.frame
qplot_crosstab(
obj,
varX,
varY,
Title = "Cross-tabulation",
xLabel = match.call()$varX,
yLabel = match.call()$varY,
...
)
# S3 method for matrix
qplot_crosstab(obj, Title = NULL, ...)
qplot_crosstab_sort(..., sort = "maxOnDiag", show.max = TRUE, shades = TRUE)
qplot_crosstab0(
tabl,
...,
sort = FALSE,
bg.color = "wheat2",
decimals = 2,
show.max = FALSE,
shades = FALSE,
guide = FALSE
)
qplot_crosstab0s(
tabl,
...,
Title = "Cross-tabulation",
xLabel = NULL,
yLabel = NULL,
subTitle = NULL,
text.size = 5,
sort = "maxOnDiag",
bg.color = "wheat2",
decimals = 2,
show.max = FALSE,
shades = FALSE,
guide = FALSE
)
(The same parameters as above).
A classification table, crosstabulation: either an object of a class "table" or a square matrix.
The main title for the plot.
A label for abscisa (x) axis.
A label for ordinate (y) axis.
The second line of title, which will be smaller and and in italics.
The size of text inside cells.
Default is FALSE
matrix is plotted as is.
Other options:
Either "maxOnDiag"
or TRUE
- function
sort_descOnDiag
is applied (rows and columns are sorted
in so that maximum values of frequencies were on diagonal, if it's
possible);"rowSums"
- sort rows by row sums;"colSums"
- sort columns by column sums;"colMax"
- sort rows in respect only to maximum value in
each row;"rowMax"
- sort columns in respect only to maximum value in
each column.
(THIS PARAMETER DO NOT WORK if as.percentage
is not
FALSE
.)
The main background color (if shade = TRUE
, this color
is used for cells with high values).
A background for maximum values.
A background for low values.
The number of decimal positions in rounding. Default is 2 (i.e., precission is 0.01).
The rule to highlighted top values. Possible entries:"max"
highlight maximum of whole matrix;"colMax"
(default) highlight maxima of every column ;"rowMax"
highlight maxima of every row;FALSE
maxima are not highlighted.
Logical. If TRUE
, color of a cell varies depending
not on its value (except the cells with top values if show.max
is FALSE
).
A type of guide to display: either "legend"
,
"colorbar"
or FALSE
(if no guide is needed).
Color of text inside cells, that have value equal to zero.
Show result as percentage:TRUE
- show as fraction of total sum;FALSE
(default) - show as frequency/counts;"col"
column-wise persentage (sum of values of each column is 100%);"row"
row-wise persentage (sum of values of each row is 100%).
of text inside cells, that have value not equal to zero.
A ggplot
object.
More details in package ggplot2.
To plot classification table (confusion matrix) use
qplot_confusion
.
Other spHelper plots:
check_palette()
,
layer_spRangeMean()
,
plot_colors()
,
plot_hyPalette()
,
plot_spCompare()
,
plot_spDiff()
,
plot_spDistribution()
,
qplot_confusion()
,
qplot_infoDim()
,
qplot_kAmp()
,
qplot_kSp()
,
qplot_prediction()
,
qplot_spRangeCenter()
,
qplot_spRangeMedian()
,
qplot_spStat()
,
qplot_spc()
,
rmExpr()
,
rm_stripes()
,
stat_chull()
# BUG for this data: when 'sort = TRUE',
# IPPN LSIL HSIL
# H.Cluster 1 0 0 111
# H.Cluster 2 0 0 45
# H.Cluster 3 0 0 49
# H.Cluster 4 0 0 5
library(spHelper)
# Generate data: Random guess ============================
N <- 1000 # number of observations
Prediction <- sample(1:4, N, replace = TRUE)
Reference <- sample(c("A", "B","C","D","E"),N, replace = TRUE)
tabl <- table(Prediction,Reference)
qplot_crosstab(tabl)
qplot_crosstab_sort(tabl) # different order of columns and rows
qplot_crosstab0(tabl) # no colors
qplot_crosstab0s(tabl) # no colors, different order of columns and rows
qplot_crosstab(Prediction, Reference, as.percentage = FALSE, sort = TRUE)
qplot_crosstab(Prediction, Reference, as.percentage = "row", sort = TRUE)
qplot_crosstab(Prediction, Reference, as.percentage = "col", sort = TRUE)
qplot_crosstab(Prediction, Reference, as.percentage = TRUE, sort = TRUE)