Skip to content
GitLab
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Earth Sciences
esviz
Compare revisions
3225ad03248b3409833c3df29e00f7392fc816ef...89aef5bde7d8eb4359679f6c5934b945ce3f4f93
Commits (6)
Add parameter sign and update code, add unit test for new parameter, update NAMESPACE
· 7ac83dce
Eva Rifà
authored
Jan 11, 2024
7ac83dce
Correct parameters colorunder and colorsup; correct subcolumn names; update description
· 4a90e6e1
Eva Rifà
authored
Jan 18, 2024
4a90e6e1
Add import RColorBrewer
· df60c905
Eva Rifà
authored
Jan 18, 2024
df60c905
Style minor change
· 19058d1b
Eva Rifà
authored
Jan 18, 2024
19058d1b
Merge branch 'develop-VizScorecards_sign' into 'main'
· cdc452eb
Eva Rifà
authored
Jan 19, 2024
Add significance in VizScorecards See merge request
!19
cdc452eb
Merge branch 'main' of
https://earth.bsc.es/gitlab/es/esviz
into develop-ShapeToMask_area
· 89aef5bd
Eva Rifà
authored
Jan 31, 2024
89aef5bd
Expand all
Hide whitespace changes
Inline
Side-by-side
NAMESPACE
View file @
89aef5bd
...
...
@@ -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)
...
...
R/VizScorecard.R
View file @
89aef5bd
This diff is collapsed.
Click to expand it.
man/VizScorecard.Rd
View file @
89aef5bd
...
...
@@ -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
indicat
in
g
the
label scal
e of the legend
values.
It is set as 1.4 by default.}
\item{label_scale}{A numeric value
to def
in
e
the
siz
e 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 d
efault.}
\item{font_size}{A numeric indicating the font size on the scorecard table.
D
efault
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
indicat
ing the width of the s
ubcolumn
header
. It is set as NULL by default.}
\item{col2_width}{A numeric value
defin
ing the width of the s
econd 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.}
...
...
tests/testthat/test-VizScorecard.R
View file @
89aef5bd
...
...
@@ -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
...
...