Commits (6)
......@@ -29,6 +29,7 @@ import(rnaturalearth)
import(sf)
import(stats)
import(utils)
importFrom(CSTools,MergeDims)
importFrom(CSTools,SplitDim)
importFrom(ClimProjDiags,Subset)
importFrom(RColorBrewer,brewer.pal)
......
This diff is collapsed.
......@@ -6,6 +6,7 @@
\usage{
VizScorecard(
data,
sign = NULL,
row_dim = "region",
subrow_dim = "time",
col_dim = "metric",
......@@ -31,6 +32,7 @@ VizScorecard(
round_decimal = 2,
font_size = 1.1,
legend_white_space = 6,
columns_width = 1.2,
col1_width = NULL,
col2_width = NULL,
fileout = "./scorecard.png"
......@@ -41,6 +43,10 @@ VizScorecard(
at least four dimensions. Each dimension will have assigned a structure
element: row, subrow, column and subcolumn.}
\item{sign}{A multidimensional boolean array with the same dimensions as
'data', indicting which values to be highlighted. If set to NULL no values
will be highlighted.}
\item{row_dim}{A character string indicating the dimension name to show in the
rows of the plot. It is set as 'region' by default.}
......@@ -90,8 +96,8 @@ colors in the scorecard table. It is set as NULL by default.}
\item{plot_legend}{A logical value to determine if the legend is plotted. It
is set as TRUE by default.}
\item{label_scale}{A numeric value indicating the label scale of the legend
values. It is set as 1.4 by default.}
\item{label_scale}{A numeric value to define the size of the legend labels.
It is set as 1.4 by default.}
\item{legend_width}{A numeric value to define the width of the legend bars. By
default it is set to NULL and calculated internally from the table width.}
......@@ -106,34 +112,40 @@ list of vectors can be given as input if different colors are desired for
the legend_dims. This parameter must be included even if the legend is
not plotted, to define the colors in the scorecard table.}
\item{colorunder}{A character string or of vector of character strings
defining the colors to use for data values with are inferior to the lowest
breaks value. This parameter will also plot a inferior triangle in the
legend bar. The parameter can be set to NULL if there are no inferior values.
If a character string is given this color will be applied to all
'legend_dims'. It is set as NULL by default.}
\item{colorsup}{A character string or of vector of character strings
defining the colors to use for data values with are superior to the highest
breaks value. This parameter will also plot a inferior triangle in the
legend bar. The parameter can be set to NULL if there are no superior values.
If a character string is given this color will be applied to all
legend_dims. It is set as NULL by default.}
\item{colorunder}{A character string, a vector of character strings or a
list with single character string elements defining the colors to use for
data values with are inferior to the lowest breaks value. This parameter
will also plot a inferior triangle in the legend bar. The parameter can be
set to NULL if there are no inferior values. If a character string is given
this color will be applied to all 'legend_dims'. It is set as NULL by
default.}
\item{colorsup}{A character string, a vector of character strings or a
list with single character string elements defining the colors to use for
data values with are superior to the highest breaks value. This parameter
will also plot a inferior triangle in the legend bar. The parameter can be
set to NULL if there are no superior values. If a character string is given
this color will be applied to all legend_dims. It is set as NULL by default.}
\item{round_decimal}{A numeric indicating to which decimal point the data
is to be displayed in the scorecard table. It is set as 2 by default.}
\item{font_size}{A numeric indicating the font size on the scorecard table. It
is set as 1.1 by default.}
\item{font_size}{A numeric indicating the font size on the scorecard table.
Default is 2.}
\item{legend_white_space}{A numeric value indicating the white space width at
the left side of the legend. The default value is 6.}
\item{legend_white_space}{A numeric value defining the initial starting
position of the legend bars, the white space infront of the legend is
calculated from the left most point of the table as a distance in cm. The
default value is 6.}
\item{col1_width}{A numeric value indicating the width of the column header.
It is set as NULL by default.}
\item{columns_width}{A numeric value defining the width all columns within the
table in cm (excluding the first and second columns containing the titles).}
\item{col1_width}{A numeric value defining the width of the first table column
in cm. It is set as NULL by default.}
\item{col2_width}{A numeric value indicating the width of the subcolumn
header. It is set as NULL by default.}
\item{col2_width}{A numeric value defining the width of the second table
column in cm. It is set as NULL by default.}
\item{fileout}{A path of the location to save the scorecard plots. By default
the plots will be saved to the working directory.}
......
......@@ -9,6 +9,10 @@ data <- array(rnorm(1000), dim = c('sdate' = 12, 'metric' = 4, 'region' = 3,
row_names <- c('Tropics', 'Extra-tropical NH', 'Extra-tropical SH')
col_names <- c('Mean bias (K)', 'Correlation', 'RPSS','CRPSS')
vals <- c(rep(T, 200), rep(F, 300), T, F, rep(T, 200), rep(F, 162))
sign <- array(vals, dim = c('sdate' = 12, 'metric' = 4, 'region' = 3,
'time' = 6))
#--------------------------------------------------------------------
test_that("1. Test input", {
# Check data
......@@ -16,6 +20,19 @@ test_that("1. Test input", {
VizScorecard('a'),
"Parameter 'data' must be a numeric array."
)
# check sign
expect_error(
VizScorecard(data = data, sign = 1, plot_legend = TRUE),
"Parameter 'sign' must be a boolean array or NULL."
)
expect_error(
VizScorecard(data, sign = array(c(T, T, F), dim = c(a = 10, b = 2))),
"Parameter 'sign' must have same dimensions as 'data'."
)
expect_error(
VizScorecard(data, sign = array(c(T, 1, F), dim = dim(data))),
"Parameter 'sign' must be an array with logical values."
)
# Check row_dim
expect_error(
VizScorecard(data, row_dim = 1),
......@@ -176,24 +193,50 @@ test_that("1. Test input", {
"Parameter 'palette' must be a character vector, a list or NULL."
)
# Check colorunder
expect_error(
VizScorecard(data, colorunder = c(1:3)),
paste0("Parameter 'colorunder' must be a character string vector or a list ",
"with the same number of elements as the length of the 'legend_dim' ",
"dimension in data.")
)
expect_error(
VizScorecard(data, colorunder = list('a', NULL, 'c')),
paste0("Parameter 'colorunder' must be a character string vector or a list ",
"with the same number of elements as the length of the 'legend_dim' ",
"dimension in data.")
)
expect_error(
VizScorecard(data, colorunder = 1),
"Parameter 'colorunder' must be a character string vector."
paste0("Parameter 'colorunder' must be a character string vector or a ",
"list of character string elements.")
)
expect_error(
VizScorecard(data, colorunder = rep('a', 5)),
paste0("Parameter 'colorunder' must be a list with the same number of ",
"elements as the length of the 'legend_dim' dimension in data.")
VizScorecard(data, colorunder = list(1)),
paste0("Parameter 'colorunder' must be a character string vector or a ",
"list of character string elements.")
)
# Check colorsup
expect_error(
VizScorecard(data, colorsup = c(1:3)),
paste0("Parameter 'colorsup' must be a character string vector or a list ",
"with the same number of elements as the length of the 'legend_dim' ",
"dimension in data.")
)
expect_error(
VizScorecard(data, colorsup = list('a', NULL, 'c')),
paste0("Parameter 'colorsup' must be a character string vector or a list ",
"with the same number of elements as the length of the 'legend_dim' ",
"dimension in data.")
)
expect_error(
VizScorecard(data, colorsup = 1),
"Parameter 'colorsup' must be a character string vector."
paste0("Parameter 'colorsup' must be a character string vector or a ",
"list of character string elements.")
)
expect_error(
VizScorecard(data, colorsup = rep('a', 5)),
paste0("Parameter 'colorsup' must be a list with the same number of ",
"elements as the length of the 'legend_dim' dimension in data.")
VizScorecard(data, colorsup = list(1)),
paste0("Parameter 'colorsup' must be a character string vector or a ",
"list of character string elements.")
)
# Check round_decimal
expect_error(
......@@ -210,6 +253,10 @@ test_that("1. Test input", {
VizScorecard(data, legend_white_space = 'a'),
"Parameter 'legend_white_space' must be a numeric value of length 1."
)
expect_error(
VizScorecard(data, columns_width = 'a'),
"Parameter 'columns_width' must be a numeric value."
)
# Check col1_width
expect_error(
VizScorecard(data, col1_width = 'a'),
......@@ -226,7 +273,7 @@ test_that("1. Test input", {
#-------------------------------------------------------------------
# NOTE: A change is detected by expect_snapshot_file but I haven't found the difference
# NOTE: A change is detected by expect_snapshot_file but there is no difference
# # Simple example
# # Example with random data
......