This is an automated email from the git hooks/post-receive script. tille pushed a commit to branch master in repository r-cran-scales.
commit c05a0562018425904b22ab416a9a74d664f42c71 Author: Andreas Tille <[email protected]> Date: Wed Oct 25 08:13:14 2017 +0200 New upstream version 0.5.0 --- DESCRIPTION | 12 +-- MD5 | 174 +++++++++++++++++++------------------ NAMESPACE | 16 +++- NEWS.md | 13 +++ R/RcppExports.R | 6 +- R/bounds.r | 94 ++++++++++++++++++-- R/breaks.r | 39 +++++++++ R/pal-viridis.r | 15 ++++ R/range.r | 27 +++--- R/scales.r | 1 - R/trans-numeric.r | 6 +- R/trans.r | 19 +++- build/partial.rdb | Bin 7869 -> 8041 bytes man/{Range-class.Rd => Range.Rd} | 15 ++-- man/abs_area.Rd | 1 - man/alpha.Rd | 1 - man/area_pal.Rd | 1 - man/as.trans.Rd | 1 - man/asn_trans.Rd | 1 - man/atanh_trans.Rd | 1 - man/boxcox_trans.Rd | 1 - man/brewer_pal.Rd | 1 - man/cbreaks.Rd | 1 - man/censor.Rd | 1 - man/col2hcl.Rd | 1 - man/col_numeric.Rd | 4 +- man/colour_ramp.Rd | 1 - man/comma_format.Rd | 3 +- man/cscale.Rd | 1 - man/date_breaks.Rd | 1 - man/date_format.Rd | 1 - man/date_trans.Rd | 1 - man/dichromat_pal.Rd | 1 - man/discard.Rd | 1 - man/div_gradient_pal.Rd | 1 - man/dollar_format.Rd | 3 +- man/dscale.Rd | 1 - man/exp_trans.Rd | 1 - man/expand_range.Rd | 1 - man/extended_breaks.Rd | 1 - man/format_format.Rd | 1 - man/fullseq.Rd | 1 - man/gradient_n_pal.Rd | 1 - man/grey_pal.Rd | 1 - man/hms_trans.Rd | 1 - man/hue_pal.Rd | 1 - man/identity_pal.Rd | 1 - man/identity_trans.Rd | 1 - man/linetype_pal.Rd | 1 - man/log1p_trans.Rd | 1 - man/log_breaks.Rd | 1 - man/log_trans.Rd | 3 +- man/manual_pal.Rd | 1 - man/math_format.Rd | 1 - man/muted.Rd | 1 - man/ordinal_format.Rd | 3 +- man/package-scales.Rd | 3 +- man/parse_format.Rd | 1 - man/percent_format.Rd | 3 +- man/pretty_breaks.Rd | 1 - man/probability_trans.Rd | 3 +- man/reciprocal_trans.Rd | 1 - man/regular_minor_breaks.Rd | 23 +++++ man/rescale.Rd | 33 +++++-- man/rescale_max.Rd | 1 - man/rescale_mid.Rd | 33 +++++-- man/rescale_none.Rd | 1 - man/rescale_pal.Rd | 1 - man/reverse_trans.Rd | 1 - man/scientific_format.Rd | 3 +- man/seq_gradient_pal.Rd | 1 - man/shape_pal.Rd | 1 - man/show_col.Rd | 1 - man/sqrt_trans.Rd | 1 - man/squish.Rd | 1 - man/squish_infinite.Rd | 1 - man/time_trans.Rd | 1 - man/train_continuous.Rd | 1 - man/train_discrete.Rd | 1 - man/trans_breaks.Rd | 1 - man/trans_format.Rd | 1 - man/trans_new.Rd | 10 ++- man/trans_range.Rd | 1 - man/unit_format.Rd | 1 - man/viridis_pal.Rd | 36 ++++++++ man/wrap_format.Rd | 1 - man/zero_range.Rd | 1 - src/RcppExports.cpp | 18 +++- tests/testthat/test-bounds.r | 48 ++++++++-- tests/testthat/test-breaks-minor.r | 17 ++++ 90 files changed, 510 insertions(+), 232 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 7b2340a..c41458e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: scales -Version: 0.4.1 +Version: 0.5.0 Authors@R: c( person("Hadley", "Wickham", , "[email protected]", c("aut", "cre")), person("RStudio", role = "cph") @@ -12,16 +12,16 @@ URL: https://github.com/hadley/scales BugReports: https://github.com/hadley/scales/issues Depends: R (>= 2.13) Imports: RColorBrewer, dichromat, plyr, munsell (>= 0.2), labeling, - methods, Rcpp + Rcpp, R6, viridisLite LinkingTo: Rcpp -Suggests: testthat (>= 0.8), covr, hms +Suggests: testthat (>= 0.8), bit64, covr, hms License: MIT + file LICENSE LazyLoad: yes -RoxygenNote: 5.0.1 +RoxygenNote: 6.0.1 NeedsCompilation: yes -Packaged: 2016-11-08 19:11:18 UTC; hadley +Packaged: 2017-08-23 21:21:31 UTC; Kara Author: Hadley Wickham [aut, cre], RStudio [cph] Maintainer: Hadley Wickham <[email protected]> Repository: CRAN -Date/Publication: 2016-11-09 18:28:56 +Date/Publication: 2017-08-24 14:35:38 UTC diff --git a/MD5 b/MD5 index d162f92..8ef7705 100644 --- a/MD5 +++ b/MD5 @@ -1,10 +1,10 @@ -c536e7133a4fa851a6b4ac8e4bd14a15 *DESCRIPTION +bb7e17bf0f58fe6c9eb060c971a5bfa4 *DESCRIPTION 5a2ffc012eac074809a07ea440f872a8 *LICENSE -be44277821c49763aa25b83f432558d1 *NAMESPACE -3136bda62246a3b53b0aa4a5d99ab225 *NEWS.md -0d76afc3c33539e2dc7e7cc8be391b61 *R/RcppExports.R -b11eaa73b921a7f0ca0b9ce412d516c8 *R/bounds.r -5dd1522b6c00411c8633cd8715a1b82b *R/breaks.r +21dc6db35bca4d6731677e8264827b0e *NAMESPACE +9dcbbdb3c657739e0dda756d86a1a224 *NEWS.md +45d9b1de49cba68e43bef09780676a9b *R/RcppExports.R +f3265470599f7082b8126eb870035fd9 *R/bounds.r +4f19c8fdcde2baeba34b9a74aa142492 *R/breaks.r 6c5942a0484c6b218a1c0b10405ac1cb *R/colour-manip.r 4a57e7d2f12a3e7aa60e8e09b0a70f66 *R/colour-mapping.r 2bfecd87cf7c8abc88ca53b3e1f1b31c *R/date-time.r @@ -22,94 +22,98 @@ a4c1f8acacabe7943df7173df7fe0633 *R/pal-linetype.r d6b7f3fb2fa5b7e87e6fe15d2869d112 *R/pal-manual.r 8cf6ec1effbef4498ee7d88ce0cbe9e2 *R/pal-rescale.r 58a8a345646e7034a6558e481defc8d6 *R/pal-shape.r -6c4b15dde8f951ed9b35431756af8cb8 *R/range.r +1b53da4e247a42eadb7c58def84bd965 *R/pal-viridis.r +235bffca636f7f6e3d66ba146407211f *R/range.r abfb1b0f1687bcdc75a9e524ce9b53d1 *R/scale-continuous.r 589b692ac75251c106e363ede654a0e5 *R/scale-discrete.r -9637a3d24c3c74a814043f55e6591fd9 *R/scales.r +1ccee0bbe83b1306707c4a5072234f42 *R/scales.r 77efc0b51a13061ab72f0a8e5b2cf197 *R/trans-date.r -3f1ec156f1cb24f09643e4d02b68d393 *R/trans-numeric.r -62abc8fd73c997d6e5e2312681b21086 *R/trans.r +19031b92f53084050230469f28521b0b *R/trans-numeric.r +539c3e75a8b9ad0bf7b22c1c2c35665a *R/trans.r 1386600336f4bc1d5c4afd74fd7e0f4d *README.md -c0df82949b2d936e58e8cf174eeca40e *build/partial.rdb -9cebb6e1cc6446e15fb87de481b439b5 *man/Range-class.Rd -cf7164e82a4551cd5b80b42025724922 *man/abs_area.Rd -96882bfa6056c0ea536a068734ffee38 *man/alpha.Rd -ace025b2b0329b6ea69fd97a17063290 *man/area_pal.Rd -fb75161f2ce5819749861f0d1b1dce3a *man/as.trans.Rd -0cbf691d42ffcf0ca7b4fa9d89d814ce *man/asn_trans.Rd -593f19f0f7495168c6093630495f861e *man/atanh_trans.Rd -c77b396cb70939d863b75c2e5479c148 *man/boxcox_trans.Rd -f0256dc779d1a7813356cd2dbde38caf *man/brewer_pal.Rd -7973693419128c1c1729d4ee9e6b3462 *man/cbreaks.Rd -75ae2a67fb1ad84826f27622abd0eb00 *man/censor.Rd -ddddab4e28bc0b4460bfd61162adc1ea *man/col2hcl.Rd -d6e7c33c2b7bc51ea2d8144e1bcc541e *man/col_numeric.Rd -fb8e4e4eb380ff3f7a74b19c97ed8e58 *man/colour_ramp.Rd -b3128c47d8f5c68d01b0263955e7081c *man/comma_format.Rd -75650f2c20aa38b63031c6b01ec8ac1c *man/cscale.Rd -57513d736051a95413f30197aeacb135 *man/date_breaks.Rd -3399ee5dd07bd5cf7c91f72fbf8ce937 *man/date_format.Rd -c515b3af1cd1f596dea26477b7856ffc *man/date_trans.Rd -8c7e64b699fbb79fbb49a53a49a8d532 *man/dichromat_pal.Rd -4e316acac9c4ccc7b852c561db901597 *man/discard.Rd -8caeef8d9bc313fe777c570fd193d208 *man/div_gradient_pal.Rd -25c6eec1cd5f84d9ee1323bf258bba56 *man/dollar_format.Rd -9afe9ab4271756529e2001bdf1cdfae4 *man/dscale.Rd -c5446cba677e2fff62fb402a1ba4c65a *man/exp_trans.Rd -c085b2a058fdd6eb72ad499005d160c4 *man/expand_range.Rd -d0783e1c6cbc8d00b8e149ff46cc2a30 *man/extended_breaks.Rd -62cad068ce4dd354f68863c57ae5bc5a *man/format_format.Rd -ae1ce88897cf6c70bee1d889cd028190 *man/fullseq.Rd -e2d157eb9a85701dc727829115d3cc8a *man/gradient_n_pal.Rd -8789d74a00daa4b600f205a9ff150ef0 *man/grey_pal.Rd -ce44f002c4ceda67dffba83725c06ee9 *man/hms_trans.Rd -ac05a22cba58a6004560d7faa1e089fd *man/hue_pal.Rd -3a183825c2e46c22ea9f738be7c4e2cd *man/identity_pal.Rd -334a28ff9d31a4c4bafd637ab22cebf3 *man/identity_trans.Rd -d02fe4b0fa7f519fdb7c9a6c33bc057d *man/linetype_pal.Rd -e21c4272d12b7186a273eff08300a413 *man/log1p_trans.Rd -0df93d5276542f986e00dc424e21a5bf *man/log_breaks.Rd -28b6b760f1a307f76dda59407d2fb4ad *man/log_trans.Rd -e935faa48f42369af11e3e3942b03607 *man/manual_pal.Rd -20284d8dd67564f838e11bdfebbf0bd8 *man/math_format.Rd -5059a7029cc84d90f7b02d36369ed14f *man/muted.Rd -b19e24b58aecd76a2b8021003b58fb5d *man/ordinal_format.Rd -d1457d632a91e2e8773ce1fa871fbab2 *man/package-scales.Rd -e45d8c20d5e5ff37409989ad5c730382 *man/parse_format.Rd -1f99e330efa1a610b46d51dd40ed1a13 *man/percent_format.Rd -7d1f9c7d88de751eeea3f2b82367f77e *man/pretty_breaks.Rd -cc9c0f7f6d250cd3f0f5746a63ea0745 *man/probability_trans.Rd -51208b85e09a5467d3366ca5031be371 *man/reciprocal_trans.Rd -3070c59456ca1b663088c6fcda017f8b *man/rescale.Rd -e19830a6384b3eb8a9e5f2a940159436 *man/rescale_max.Rd -db815f8eb56f6350ae567c14bb42ef66 *man/rescale_mid.Rd -3af70efd513587e6eb9f2d255667d914 *man/rescale_none.Rd -eeb3100220dd856a20bc665d2e8272be *man/rescale_pal.Rd -d559d1a58999f12087878b6e3c5d1a76 *man/reverse_trans.Rd -95fa00d20a410bf1cf63f07fcd46d25f *man/scientific_format.Rd -2eb00f2a459f9bedd4accec0025b099f *man/seq_gradient_pal.Rd -2e53f06e9802c200a3b1bc5a212562ba *man/shape_pal.Rd -cbc7b40e6922f8d7d3ded0e7f79d22b0 *man/show_col.Rd -f5097c06dadbc32103b01a846899f6b1 *man/sqrt_trans.Rd -0376ff9300898a3cc3d19b4735bbd447 *man/squish.Rd -70f53a5242b480a25411d156f5fbf24a *man/squish_infinite.Rd -192635ddd9b1a2ff6cd0a64447127210 *man/time_trans.Rd -2e9b19fddb8f762acbd357759f77049c *man/train_continuous.Rd -311128aaca1b09b5eb4858fc0b8880c4 *man/train_discrete.Rd -17078f916904432680cea7e716d65cae *man/trans_breaks.Rd -4a9b85fe979a0ec1ca40cdcd1555f73a *man/trans_format.Rd -aac3ecd802efcede4a24a1735d6520ef *man/trans_new.Rd -a4c05123a59924a6b3e9bc02ee5c8bbe *man/trans_range.Rd -5f0cade40a6995b50a1d1fd969b4764d *man/unit_format.Rd -04e34ca3cedbb591e96244b0068dd6ea *man/wrap_format.Rd -3086e5a29c13333160634a6b8147ea18 *man/zero_range.Rd -f3983f4241cd06de6427edb3e53a3ecb *src/RcppExports.cpp +91f3d2b15c7986607ff5363ffc82c136 *build/partial.rdb +e960aeea59e5785c03ec7d539e5064b7 *man/Range.Rd +a143f766fadeb7004d27772730837955 *man/abs_area.Rd +5b771962edc19bf1c4c0fe1da257d9ab *man/alpha.Rd +3c9ad78a6366d63b3b545b41a114f57d *man/area_pal.Rd +51046cf445ec3d0e1c21fe5345013d13 *man/as.trans.Rd +0bd187febee73a93bc0930ff8864b4d3 *man/asn_trans.Rd +942f1cb05d0fd33bedbec2f2168c33f8 *man/atanh_trans.Rd +7501e4c47db21ec8e50f86c3f5677504 *man/boxcox_trans.Rd +bf5d724a2225f9099c5bbb9caaa000ef *man/brewer_pal.Rd +c6bb712c014caa883e2b52c60facf6d6 *man/cbreaks.Rd +6f865bfb28147e39dc1e005d88708905 *man/censor.Rd +4b6f674f19423b0f1503d2091dc90b9e *man/col2hcl.Rd +aee7e13f7987ceaf353bfbb0d35cbf8f *man/col_numeric.Rd +da54e93f1953f814e05c64adaa6e6aaa *man/colour_ramp.Rd +c5d300ecd1947894c9e6add2aa6ad54f *man/comma_format.Rd +42a2b39e94a28054d8c1525b1817a586 *man/cscale.Rd +d819416ec7146602723c45ad817f8b16 *man/date_breaks.Rd +0643dfcc790518dfc588054bc8a3fe45 *man/date_format.Rd +0f848f858c831e645100cbdc2b105bc7 *man/date_trans.Rd +5d8909784c1daf22b0b356643c0549c7 *man/dichromat_pal.Rd +286890abf9cb397ce5f334cbddf165fd *man/discard.Rd +0b0dff89262b0ef3044632bc2c3baf03 *man/div_gradient_pal.Rd +a318b237093e8218b434642356d1460d *man/dollar_format.Rd +a659db7c5108be4bb04583b7fcb0e060 *man/dscale.Rd +6512ff996494e76c2a22e17bbd2f391a *man/exp_trans.Rd +89823c481ecc3ba5f92c6cf8134fb224 *man/expand_range.Rd +ded1e6dd7787fdd336eddf3c9632c555 *man/extended_breaks.Rd +273bb64ba1e7e0bd53dc1ccbcc791dcf *man/format_format.Rd +b24a64bdf91ffaf48638f30457a9a3aa *man/fullseq.Rd +8c9f52f2c8caa4cca3034962c2e4d4bd *man/gradient_n_pal.Rd +9bcff3ccdcf08a21faf2691ba4342d64 *man/grey_pal.Rd +085d07253dd27880aee5b3cc4b473b17 *man/hms_trans.Rd +e3a055014ae892b78878dbd265245c8c *man/hue_pal.Rd +fa000569ad9743d144b97a9dc10a30c2 *man/identity_pal.Rd +fc73bc1a6045bd4bb2838b799904b928 *man/identity_trans.Rd +56355fbfe52a570286a2187caad97161 *man/linetype_pal.Rd +17e8580fa4b543529526a160d1d19ab7 *man/log1p_trans.Rd +62932d4e16459a3a68c2393850207218 *man/log_breaks.Rd +372501ebff80335927418d51723aa7fd *man/log_trans.Rd +5fee45515c493bdae29ae9b58ad26c94 *man/manual_pal.Rd +75942253a0c83e7df20aad7d57c6674b *man/math_format.Rd +7da73d6a111314c5b34d6bfdfd5482d8 *man/muted.Rd +7c70f3d3fb73f5fc0c13924c1c9f6c26 *man/ordinal_format.Rd +21a18c78aa327d7ab22139feeb68a7f9 *man/package-scales.Rd +32d22f69a169d07da12f5e4a5916cd1c *man/parse_format.Rd +e94a0233432abe6ef89ceea03c4363f4 *man/percent_format.Rd +6b611492dacca8f70cf65143cbda73fc *man/pretty_breaks.Rd +f486bc364f59b6a465b0c51a8077df1e *man/probability_trans.Rd +2eb728b9cfdb86d43ff04ba5519a9ba4 *man/reciprocal_trans.Rd +b6579c0df88f115a382e3c003694f0ad *man/regular_minor_breaks.Rd +632b2afcce7cf202d67a3169ed2e7caf *man/rescale.Rd +dd8d919f00d419e6580f2d6bdd42a4c6 *man/rescale_max.Rd +6b38a393b57dcaa06ed8f48760499c6f *man/rescale_mid.Rd +523c1c3d4420f9940edff7ac3cb42290 *man/rescale_none.Rd +48cf3f041266b047e8666a297585b471 *man/rescale_pal.Rd +481ccee1e6f8f750398bf589df6438bc *man/reverse_trans.Rd +0bdd43f4847ec185968c278bf7a5411b *man/scientific_format.Rd +bd95599bf4eadd56b016e8eff70a44fd *man/seq_gradient_pal.Rd +cf6817de3c36b57c8be764722e0ab7a0 *man/shape_pal.Rd +8223dcf047091e96fbd9d4af44ccf894 *man/show_col.Rd +51eb8f0f50040ef782ab3063b58290bb *man/sqrt_trans.Rd +692d3a327da1cce9e9e457c1438f0855 *man/squish.Rd +eb50452ed9f4ac7f536f861086a49f37 *man/squish_infinite.Rd +998b225feb6311828125eb909fb0ab9c *man/time_trans.Rd +8af93864036e45e011e0288150c0e574 *man/train_continuous.Rd +2f6bd2c10e0f2073b5dff0a7c9c2a5df *man/train_discrete.Rd +289f9dee4095c0678ffd8ee8ddb9fd50 *man/trans_breaks.Rd +2eaf34121713fb5c881cc6ebfc80572f *man/trans_format.Rd +764d8e6bf14fc755e2c102cb24bd7bd3 *man/trans_new.Rd +d2385f74fbbed665403072edbbc3a980 *man/trans_range.Rd +464f92ee3ce93fad8fb794b537be1a70 *man/unit_format.Rd +50c65a8393d1b32bd8cbe6e652c2ba97 *man/viridis_pal.Rd +348b475f786b7da72c2677152cec3899 *man/wrap_format.Rd +710ff73a1292b593f1bf24fc8f261064 *man/zero_range.Rd +b5725c008a144f333f1f94a94876c86a *src/RcppExports.cpp 50b694b150f1cc631e68e0c471b1737b *src/colors.cpp 1bc97669868c55fc86b10bffb2010b63 *tests/testthat.R 9b1f7ff67006d13e255f222feba5ee9e *tests/testthat/test-alpha.r -210d4b72f91809cb8c82a36d60eff279 *tests/testthat/test-bounds.r +e1b0934110ab4e19d15a4a2aa1eb2865 *tests/testthat/test-bounds.r 9d3de74dea77f40ad053834c04b824be *tests/testthat/test-breaks-extended.R b5bb7a6051319394602be12701d8b845 *tests/testthat/test-breaks-log.r +051d2a442a202d5315680d48bce97596 *tests/testthat/test-breaks-minor.r 361eca6c9ef2ec2361364c81ff4a39cc *tests/testthat/test-colors.r fa5466f6b3cf5c5e7dd187b32c049408 *tests/testthat/test-colour-ramp.R 1251432e702c697a211f0117e340051e *tests/testthat/test-discrete.R diff --git a/NAMESPACE b/NAMESPACE index 9dafe0e..18c4e7e 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -4,6 +4,18 @@ S3method(fullseq,Date) S3method(fullseq,POSIXt) S3method(fullseq,numeric) S3method(print,trans) +S3method(rescale,"NULL") +S3method(rescale,Date) +S3method(rescale,POSIXt) +S3method(rescale,integer64) +S3method(rescale,logical) +S3method(rescale,numeric) +S3method(rescale_mid,"NULL") +S3method(rescale_mid,Date) +S3method(rescale_mid,POSIXt) +S3method(rescale_mid,integer64) +S3method(rescale_mid,logical) +S3method(rescale_mid,numeric) export(ContinuousRange) export(DiscreteRange) export(abs_area) @@ -65,6 +77,7 @@ export(pretty_breaks) export(probability_trans) export(probit_trans) export(reciprocal_trans) +export(regular_minor_breaks) export(rescale) export(rescale_max) export(rescale_mid) @@ -87,6 +100,7 @@ export(trans_format) export(trans_new) export(trans_range) export(unit_format) +export(viridis_pal) export(wrap_format) export(zero_range) importFrom(Rcpp,evalCpp) @@ -94,8 +108,6 @@ importFrom(graphics,par) importFrom(graphics,plot) importFrom(graphics,rect) importFrom(graphics,text) -importFrom(methods,new) -importFrom(methods,setRefClass) importFrom(munsell,mnsl) importFrom(plyr,is.discrete) importFrom(plyr,round_any) diff --git a/NEWS.md b/NEWS.md index 4b135f0..4629cbc 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,16 @@ +# scales 0.5.0 + +* New function `regular_minor_breaks()` calculates minor breaks as a property + of the transformation (@karawoo). + +* Adds `viridis_pal()` for creating palettes with color maps from the + viridisLite package (@karawoo). + +* Switched from reference classes to R6 (#96). + +* `rescale()` and `rescale_mid()` are now S3 generics, and work with `numeric`, + `Date`, `POSIXct`, `POSIXlt` and `bit64::integer64` objects (@zeehio, #74). + # scales 0.4.1 * `extended_breaks()` no longer fails on pathological inputs diff --git a/R/RcppExports.R b/R/RcppExports.R index c749b81..8d672b8 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -2,14 +2,14 @@ # Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 doColorRamp <- function(colors, x, alpha, naColor) { - .Call('scales_doColorRamp', PACKAGE = 'scales', colors, x, alpha, naColor) + .Call('_scales_doColorRamp', PACKAGE = 'scales', colors, x, alpha, naColor) } rgbToLab <- function(rgb) { - .Call('scales_rgbToLab', PACKAGE = 'scales', rgb) + .Call('_scales_rgbToLab', PACKAGE = 'scales', rgb) } rgbToXyz <- function(rgb) { - .Call('scales_rgbToXyz', PACKAGE = 'scales', rgb) + .Call('_scales_rgbToXyz', PACKAGE = 'scales', rgb) } diff --git a/R/bounds.r b/R/bounds.r index 5407f08..c18cc58 100644 --- a/R/bounds.r +++ b/R/bounds.r @@ -1,42 +1,120 @@ -#' Rescale numeric vector to have specified minimum and maximum. +#' Rescale continuous vector to have specified minimum and maximum. #' -#' @param x numeric vector of values to manipulate. +#' @param x continuous vector of values to manipulate. #' @param to output range (numeric vector of length two) -#' @param from input range (numeric vector of length two). If not given, is +#' @param from input range (vector of length two). If not given, is #' calculated from the range of \code{x} +#' @param ... other arguments passed on to methods #' @keywords manip #' @export #' @examples #' rescale(1:100) #' rescale(runif(50)) #' rescale(1) -rescale <- function(x, to = c(0, 1), from = range(x, na.rm = TRUE, finite = TRUE)) { +rescale <- function(x, to, from, ...) { + UseMethod("rescale") +} + + +#' @rdname rescale +#' @export +rescale.numeric <- function(x, to = c(0, 1), from = range(x, na.rm = TRUE, finite = TRUE), ...) { if (zero_range(from) || zero_range(to)) { return(ifelse(is.na(x), NA, mean(to))) } + (x - from[1]) / diff(from) * diff(to) + to[1] +} + +#' @export +rescale.NULL <- function(...) NULL + +#' @rdname rescale +#' @export +rescale.logical <- rescale.numeric + +#' @rdname rescale +#' @export +rescale.POSIXt <- function(x, to = c(0, 1), from = range(x, na.rm = TRUE, finite = TRUE), ...) { + x <- as.numeric(x) + from <- as.numeric(from) + rescale.numeric(x = x, to = to, from = from) +} + +#' @rdname rescale +#' @export +rescale.Date <- rescale.POSIXt +#' @rdname rescale +#' @export +rescale.integer64 <- function(x, to = c(0, 1), from = range(x, na.rm = TRUE), ...) { + if (zero_range(from, tol = 0) || zero_range(to)) { + return(ifelse(is.na(x), NA, mean(to))) + } (x - from[1]) / diff(from) * diff(to) + to[1] } -#' Rescale numeric vector to have specified minimum, midpoint, and maximum. + +#' Rescale vector to have specified minimum, midpoint, and maximum. #' #' @export -#' @param x numeric vector of values to manipulate. +#' @param x vector of values to manipulate. #' @param to output range (numeric vector of length two) -#' @param from input range (numeric vector of length two). If not given, is +#' @param from input range (vector of length two). If not given, is #' calculated from the range of \code{x} #' @param mid mid-point of input range +#' @param ... other arguments passed on to methods #' @examples #' rescale_mid(1:100, mid = 50.5) #' rescale_mid(runif(50), mid = 0.5) #' rescale_mid(1) -rescale_mid <- function(x, to = c(0, 1), from = range(x, na.rm = TRUE), mid = 0) { +rescale_mid <- function(x, to, from, mid, ...) { + UseMethod("rescale_mid") +} + +#' @rdname rescale_mid +#' @export +rescale_mid.numeric <- function(x, to = c(0, 1), from = range(x, na.rm = TRUE), mid = 0, ...) { if (zero_range(from) || zero_range(to)) return(rep(mean(to), length(x))) extent <- 2 * max(abs(from - mid)) (x - mid) / extent * diff(to) + mean(to) } +#' @export +rescale_mid.NULL <- function(...) NULL + +#' @rdname rescale_mid +#' @export +rescale_mid.logical <- rescale_mid.numeric + +#' @rdname rescale_mid +#' @export +rescale_mid.POSIXt <- function(x, to = c(0, 1), from = range(x, na.rm = TRUE), + mid, ...) { + x <- as.numeric(as.POSIXct(x)) + if (!is.numeric(from)) { + from <- as.numeric(as.POSIXct(from)) + } + if (!is.numeric(mid)) { + mid <- as.numeric(as.POSIXct(mid)) + } + rescale_mid.numeric(x = x, to = to, from = from, mid = mid) +} + +#' @rdname rescale_mid +#' @export +rescale_mid.Date <- rescale_mid.POSIXt + +#' @rdname rescale_mid +#' @export +rescale_mid.integer64 <- function(x, to = c(0, 1), from = range(x, na.rm = TRUE), mid = 0, ...) { + if (zero_range(from, tol = 0) || zero_range(to)) return(rep(mean(to), length(x))) + + extent <- 2 * max(abs(from - mid)) + (x - mid) / extent * diff(to) + mean(to) +} + + #' Rescale numeric vector to have specified maximum. #' #' @export diff --git a/R/breaks.r b/R/breaks.r index 2e4e701..474893b 100644 --- a/R/breaks.r +++ b/R/breaks.r @@ -150,3 +150,42 @@ cbreaks <- function(range, breaks = extended_breaks(), labels = scientific_forma list(breaks = breaks, labels = labels) } + +#' Minor breaks +#' Places minor breaks between major breaks. +#' +#' @param reverse if TRUE, calculates the minor breaks for a reversed scale +#' @export +#' @examples +#' m <- extended_breaks()(c(1, 10)) +#' regular_minor_breaks()(m, c(1, 10), n = 2) +#' +#' n <- extended_breaks()(c(0, -9)) +#' regular_minor_breaks(reverse = TRUE)(n, c(0, -9), n = 2) +regular_minor_breaks <- function(reverse = FALSE) { + function(b, limits, n) { + b <- b[!is.na(b)] + if (length(b) < 2) return() + + bd <- diff(b)[1] + + # Allow minor breaks to extend outside major breaks towards limits + if (!reverse) { + if (min(limits) < min(b)) b <- c(b[1] - bd, b) + if (max(limits) > max(b)) b <- c(b, b[length(b)] + bd) + } else { + if (max(limits) > max(b)) b <- c(b[1] - bd, b) + if (min(limits) < min(b)) b <- c(b, b[length(b)] + bd) + } + + # Find minor breaks between major breaks + seq_between <- function(a, b) { + seq(a, b, length.out = n + 1)[-(n + 1)] + } + breaks <- unlist(Map(seq_between, b[-length(b)], b[-1])) + + # Add the final break back + breaks <- c(breaks, b[length(b)]) + breaks + } +} diff --git a/R/pal-viridis.r b/R/pal-viridis.r new file mode 100644 index 0000000..85dafd3 --- /dev/null +++ b/R/pal-viridis.r @@ -0,0 +1,15 @@ +#' Viridis palette +#' +#' @inheritParams viridisLite::viridis +#' @references \url{https://bids.github.io/colormap/} +#' @export +#' @examples +#' show_col(viridis_pal()(10)) +#' show_col(viridis_pal(direction = -1)(6)) +#' show_col(viridis_pal(begin = 0.2, end = 0.8)(4)) +#' show_col(viridis_pal(option = "plasma")(6)) +viridis_pal <- function(alpha = 1, begin = 0, end = 1, direction = 1, option= "D") { + function(n) { + viridisLite::viridis(n, alpha, begin, end, direction, option) + } +} diff --git a/R/range.r b/R/range.r index 20f0b94..4148b50 100644 --- a/R/range.r +++ b/R/range.r @@ -5,26 +5,29 @@ #' #' @aliases DiscreteRange ContinuousRange #' @export DiscreteRange ContinuousRange -Range <- methods::setRefClass("Range", fields = "range", methods = list( +Range <- R6::R6Class("Range", list( + range = NULL, initialize = function() { - initFields(range = NULL) + self$range <- NULL }) ) -DiscreteRange <- methods::setRefClass( - "DiscreteRange", contains = "Range", - methods = list( +DiscreteRange <- R6::R6Class( + "DiscreteRange", + inherit = "Range", + list( train = function(x, drop = FALSE) { - range <<- train_discrete(x, range, drop) + self$range <- train_discrete(x, range, drop) }, - reset = function() range <<- NULL + reset = function() self$range <- NULL ) ) -ContinuousRange <- methods::setRefClass( - "Continuous", contains = "Range", - methods = list( - train = function(x) range <<- train_continuous(x, range), - reset = function() range <<- NULL +ContinuousRange <- R6::R6Class( + "ContinuousRange", + inherit = "Range", + list( + train = function(x) self$range <- train_continuous(x, range), + reset = function() self$range <- NULL ) ) diff --git a/R/scales.r b/R/scales.r index a6961e5..082f0c1 100644 --- a/R/scales.r +++ b/R/scales.r @@ -4,7 +4,6 @@ #' @name package-scales #' @aliases scales package-scales #' @useDynLib scales -#' @importFrom methods setRefClass new #' @importFrom plyr round_any is.discrete #' @importFrom Rcpp evalCpp NULL diff --git a/R/trans-numeric.r b/R/trans-numeric.r index 15a02bc..5b02e6a 100644 --- a/R/trans-numeric.r +++ b/R/trans-numeric.r @@ -111,7 +111,11 @@ reciprocal_trans <- function() { #' #' @export reverse_trans <- function() { - trans_new("reverse", function(x) -x, function(x) -x) + trans_new( + "reverse", + function(x) -x, + function(x) -x, + minor_breaks = regular_minor_breaks(reverse = TRUE)) } #' Square-root transformation. diff --git a/R/trans.r b/R/trans.r index 8d6354d..2de4373 100644 --- a/R/trans.r +++ b/R/trans.r @@ -14,6 +14,7 @@ #' inverse of the transformation #' @param breaks default breaks function for this transformation. The breaks #' function is applied to the raw data. +#' @param minor_breaks default minor breaks function for this transformation. #' @param format default format for this transformation. The format is applied #' to breaks generated to the raw data. #' @param domain domain, as numeric vector of length 2, over which @@ -21,13 +22,23 @@ #' @seealso \Sexpr[results=rd,stage=build]{scales:::seealso_trans()} #' @export trans_new is.trans #' @aliases trans_new trans is.trans -trans_new <- function(name, transform, inverse, breaks = extended_breaks(), format = format_format(), domain = c(-Inf, Inf)) { +trans_new <- function(name, transform, inverse, breaks = extended_breaks(), + minor_breaks = regular_minor_breaks(), + format = format_format(), domain = c(-Inf, Inf)) { if (is.character(transform)) transform <- match.fun(transform) if (is.character(inverse)) inverse <- match.fun(inverse) - structure(list(name = name, transform = transform, inverse = inverse, - breaks = breaks, format = format, domain = domain), - class = "trans") + structure( + list( + name = name, + transform = transform, + inverse = inverse, + breaks = breaks, + minor_breaks = minor_breaks, + format = format, + domain = domain), + class = "trans" + ) } is.trans <- function(x) inherits(x, "trans") diff --git a/build/partial.rdb b/build/partial.rdb index 5f59257..8f3bf41 100644 Binary files a/build/partial.rdb and b/build/partial.rdb differ diff --git a/man/Range-class.Rd b/man/Range.Rd similarity index 71% rename from man/Range-class.Rd rename to man/Range.Rd index ad2a9b5..288f07a 100644 --- a/man/Range-class.Rd +++ b/man/Range.Rd @@ -1,14 +1,17 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/range.r -\docType{class} -\name{Range-class} -\alias{ContinuousRange} -\alias{DiscreteRange} +\docType{data} +\name{Range} \alias{Range} -\alias{Range-class} +\alias{DiscreteRange} +\alias{ContinuousRange} \title{Mutable ranges.} +\format{An object of class \code{R6ClassGenerator} of length 24.} +\usage{ +Range +} \description{ Mutable ranges have a two methods (\code{train} and \code{reset}), and make it possible to build up complete ranges with multiple passes. } - +\keyword{datasets} diff --git a/man/abs_area.Rd b/man/abs_area.Rd index 185f259..7708c1e 100644 --- a/man/abs_area.Rd +++ b/man/abs_area.Rd @@ -12,4 +12,3 @@ abs_area(max) \description{ Point area palette (continuous), with area proportional to value. } - diff --git a/man/alpha.Rd b/man/alpha.Rd index e0156e3..e4cd1d4 100644 --- a/man/alpha.Rd +++ b/man/alpha.Rd @@ -22,4 +22,3 @@ alpha("red", 0.1) alpha(colours(), 0.5) alpha("red", seq(0, 1, length.out = 10)) } - diff --git a/man/area_pal.Rd b/man/area_pal.Rd index 643f44d..d24678b 100644 --- a/man/area_pal.Rd +++ b/man/area_pal.Rd @@ -13,4 +13,3 @@ Should be greater than 0.} \description{ Point area palette (continuous). } - diff --git a/man/as.trans.Rd b/man/as.trans.Rd index ce2ceeb..8259dc9 100644 --- a/man/as.trans.Rd +++ b/man/as.trans.Rd @@ -12,4 +12,3 @@ as.trans(x) \description{ Convert character string to transformer. } - diff --git a/man/asn_trans.Rd b/man/asn_trans.Rd index 344b2ee..d23a8ad 100644 --- a/man/asn_trans.Rd +++ b/man/asn_trans.Rd @@ -9,4 +9,3 @@ asn_trans() \description{ Arc-sin square root transformation. } - diff --git a/man/atanh_trans.Rd b/man/atanh_trans.Rd index 2de78f7..168bb4f 100644 --- a/man/atanh_trans.Rd +++ b/man/atanh_trans.Rd @@ -9,4 +9,3 @@ atanh_trans() \description{ Arc-tangent transformation. } - diff --git a/man/boxcox_trans.Rd b/man/boxcox_trans.Rd index 459c87f..fe7f396 100644 --- a/man/boxcox_trans.Rd +++ b/man/boxcox_trans.Rd @@ -15,4 +15,3 @@ Box-Cox power transformation. \references{ See \url{http://en.wikipedia.org/wiki/Power_transform} for } - diff --git a/man/brewer_pal.Rd b/man/brewer_pal.Rd index d2cff02..2f67611 100644 --- a/man/brewer_pal.Rd +++ b/man/brewer_pal.Rd @@ -31,4 +31,3 @@ show_col(gradient_n_pal(cols)(seq(0, 1, length.out = 30))) \references{ \url{http://colorbrewer2.org} } - diff --git a/man/cbreaks.Rd b/man/cbreaks.Rd index 913d5a4..d6a123a 100644 --- a/man/cbreaks.Rd +++ b/man/cbreaks.Rd @@ -42,4 +42,3 @@ cbreaks(c(0, 100), breaks = c(15, 20, 80), labels = c(1.5, 2.0, 8.0)) cbreaks(c(0, 100), breaks = c(15, 20, 80), labels = expression(alpha, beta, gamma)) } - diff --git a/man/censor.Rd b/man/censor.Rd index b79895e..c29deff 100644 --- a/man/censor.Rd +++ b/man/censor.Rd @@ -20,4 +20,3 @@ Censor any values outside of range. \examples{ censor(c(-1, 0.5, 1, 2, NA)) } - diff --git a/man/col2hcl.Rd b/man/col2hcl.Rd index d94b730..9ad236e 100644 --- a/man/col2hcl.Rd +++ b/man/col2hcl.Rd @@ -24,4 +24,3 @@ to rgb. \examples{ col2hcl(colors()) } - diff --git a/man/col_numeric.Rd b/man/col_numeric.Rd index f9d5899..57b5829 100644 --- a/man/col_numeric.Rd +++ b/man/col_numeric.Rd @@ -1,10 +1,11 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/colour-mapping.r \name{col_numeric} +\alias{col_numeric} \alias{col_bin} +\alias{col_quantile} \alias{col_factor} \alias{col_numeric} -\alias{col_quantile} \title{Color mapping} \usage{ col_numeric(palette, domain, na.color = "#808080") @@ -105,4 +106,3 @@ show_col(col_factor("RdYlBu", domain = NULL)(factor(LETTERS[1:5], levels=LETTERS # ...or the domain is stated explicitly. show_col(col_factor("RdYlBu", levels = LETTERS)(LETTERS[1:5])) } - diff --git a/man/colour_ramp.Rd b/man/colour_ramp.Rd index 6dfbf4c..02e50ac 100644 --- a/man/colour_ramp.Rd +++ b/man/colour_ramp.Rd @@ -37,4 +37,3 @@ times faster, and provides results in \code{"#RRGGBB"} (or \seealso{ \link[grDevices]{colorRamp} } - diff --git a/man/comma_format.Rd b/man/comma_format.Rd index 3587c1a..b6bd25f 100644 --- a/man/comma_format.Rd +++ b/man/comma_format.Rd @@ -1,8 +1,8 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/formatter.r \name{comma_format} -\alias{comma} \alias{comma_format} +\alias{comma} \title{Comma formatter: format number with commas separating thousands.} \usage{ comma_format(...) @@ -32,4 +32,3 @@ point <- format_format(big.mark = ".", decimal.mark = ",", scientific = FALSE) point(c(1, 1e3, 2000, 1e6)) point(c(1, 1.021, 1000.01)) } - diff --git a/man/cscale.Rd b/man/cscale.Rd index fd4c188..6bf4f9c 100644 --- a/man/cscale.Rd +++ b/man/cscale.Rd @@ -34,4 +34,3 @@ with(mtcars, plot(disp, mpg, cex = cscale(hp, area_pal()))) with(mtcars, plot(disp, mpg, pch = 20, cex = 5, col = cscale(hp, seq_gradient_pal("grey80", "black")))) } - diff --git a/man/date_breaks.Rd b/man/date_breaks.Rd index 737fd4a..5da61e7 100644 --- a/man/date_breaks.Rd +++ b/man/date_breaks.Rd @@ -14,4 +14,3 @@ followed by "s".} \description{ Regularly spaced dates. } - diff --git a/man/date_format.Rd b/man/date_format.Rd index eb0c9e7..d7fe45b 100644 --- a/man/date_format.Rd +++ b/man/date_format.Rd @@ -16,4 +16,3 @@ to UTC} \description{ Formatted dates. } - diff --git a/man/date_trans.Rd b/man/date_trans.Rd index b11a399..292d298 100644 --- a/man/date_trans.Rd +++ b/man/date_trans.Rd @@ -16,4 +16,3 @@ t$transform(years) t$inverse(t$transform(years)) t$format(t$breaks(range(years))) } - diff --git a/man/dichromat_pal.Rd b/man/dichromat_pal.Rd index 8cdfa2d..ce59ec5 100644 --- a/man/dichromat_pal.Rd +++ b/man/dichromat_pal.Rd @@ -21,4 +21,3 @@ show_col(dichromat_pal("BluetoOrange.10")(5)) cols <- dichromat_pal("DarkRedtoBlue.12")(12) show_col(gradient_n_pal(cols)(seq(0, 1, length.out = 30))) } - diff --git a/man/discard.Rd b/man/discard.Rd index 08b6bff..8e9b49e 100644 --- a/man/discard.Rd +++ b/man/discard.Rd @@ -17,4 +17,3 @@ Discard any values outside of range. \examples{ discard(c(-1, 0.5, 1, 2, NA)) } - diff --git a/man/div_gradient_pal.Rd b/man/div_gradient_pal.Rd index fd0048e..69033f3 100644 --- a/man/div_gradient_pal.Rd +++ b/man/div_gradient_pal.Rd @@ -31,4 +31,3 @@ library(munsell) image(r, col = div_gradient_pal(low = mnsl(complement("10R 4/6", fix = TRUE)))(seq(0, 1, length = 100))) } - diff --git a/man/dollar_format.Rd b/man/dollar_format.Rd index 870917f..edb5da1 100644 --- a/man/dollar_format.Rd +++ b/man/dollar_format.Rd @@ -1,8 +1,8 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/formatter.r \name{dollar_format} -\alias{dollar} \alias{dollar_format} +\alias{dollar} \title{Currency formatter: round to nearest cent and display dollar sign.} \usage{ dollar_format(prefix = "$", suffix = "", largest_with_cents = 1e+05, ..., @@ -50,4 +50,3 @@ euro(100) finance <- dollar_format(negative_parens = TRUE) finance(c(-100, 100)) } - diff --git a/man/dscale.Rd b/man/dscale.Rd index 573d1a3..1881cad 100644 --- a/man/dscale.Rd +++ b/man/dscale.Rd @@ -20,4 +20,3 @@ Discrete scale. with(mtcars, plot(disp, mpg, pch = 20, cex = 3, col = dscale(factor(cyl), brewer_pal()))) } - diff --git a/man/exp_trans.Rd b/man/exp_trans.Rd index 25c767f..a235512 100644 --- a/man/exp_trans.Rd +++ b/man/exp_trans.Rd @@ -12,4 +12,3 @@ exp_trans(base = exp(1)) \description{ Exponential transformation (inverse of log transformation). } - diff --git a/man/expand_range.Rd b/man/expand_range.Rd index db8490d..495b5d4 100644 --- a/man/expand_range.Rd +++ b/man/expand_range.Rd @@ -18,4 +18,3 @@ expand_range(range, mul = 0, add = 0, zero_width = 1) \description{ Expand a range with a multiplicative or additive constant. } - diff --git a/man/extended_breaks.Rd b/man/extended_breaks.Rd index f053620..8eabd67 100644 --- a/man/extended_breaks.Rd +++ b/man/extended_breaks.Rd @@ -27,4 +27,3 @@ Talbot, J., Lin, S., Hanrahan, P. (2010) An Extension of Wilkinson's Algorithm for Positioning Tick Labels on Axes, InfoVis 2010. } - diff --git a/man/format_format.Rd b/man/format_format.Rd index 98ac088..5b00fd9 100644 --- a/man/format_format.Rd +++ b/man/format_format.Rd @@ -17,4 +17,3 @@ the breaks. \code{\link{format}}, \code{\link{format.Date}}, \code{\link{format.POSIXct}} } - diff --git a/man/fullseq.Rd b/man/fullseq.Rd index f1e69b5..f0d4f10 100644 --- a/man/fullseq.Rd +++ b/man/fullseq.Rd @@ -20,4 +20,3 @@ Generate sequence of fixed size intervals covering range. \code{\link[plyr]{round_any}} } \keyword{internal} - diff --git a/man/gradient_n_pal.Rd b/man/gradient_n_pal.Rd index ceca85e..4ec5cf1 100644 --- a/man/gradient_n_pal.Rd +++ b/man/gradient_n_pal.Rd @@ -20,4 +20,3 @@ other values are deprecated.} \description{ Arbitrary colour gradient palette (continous). } - diff --git a/man/grey_pal.Rd b/man/grey_pal.Rd index ff156e8..cc921b8 100644 --- a/man/grey_pal.Rd +++ b/man/grey_pal.Rd @@ -21,4 +21,3 @@ show_col(grey_pal(0, 1)(25)) \seealso{ \code{\link{seq_gradient_pal}} for continuous version } - diff --git a/man/hms_trans.Rd b/man/hms_trans.Rd index 9fd3035..a68237b 100644 --- a/man/hms_trans.Rd +++ b/man/hms_trans.Rd @@ -18,4 +18,3 @@ t$inverse(t$transform(hms)) t$breaks(hms) } } - diff --git a/man/hue_pal.Rd b/man/hue_pal.Rd index 193728f..8bd2ef5 100644 --- a/man/hue_pal.Rd +++ b/man/hue_pal.Rd @@ -38,4 +38,3 @@ show_col(hue_pal(h = c(90, 180))(9)) show_col(hue_pal(h = c(180, 270))(9)) show_col(hue_pal(h = c(270, 360))(9)) } - diff --git a/man/identity_pal.Rd b/man/identity_pal.Rd index 950babe..fa8cfe0 100644 --- a/man/identity_pal.Rd +++ b/man/identity_pal.Rd @@ -9,4 +9,3 @@ identity_pal() \description{ Leaves values unchanged - useful when the data is already scaled. } - diff --git a/man/identity_trans.Rd b/man/identity_trans.Rd index e0ea625..72bb6e5 100644 --- a/man/identity_trans.Rd +++ b/man/identity_trans.Rd @@ -9,4 +9,3 @@ identity_trans() \description{ Identity transformation (do nothing). } - diff --git a/man/linetype_pal.Rd b/man/linetype_pal.Rd index a319906..e1e2e02 100644 --- a/man/linetype_pal.Rd +++ b/man/linetype_pal.Rd @@ -9,4 +9,3 @@ linetype_pal() \description{ Based on a set supplied by Richard Pearson, University of Manchester } - diff --git a/man/log1p_trans.Rd b/man/log1p_trans.Rd index 0d74c14..f38f71d 100644 --- a/man/log1p_trans.Rd +++ b/man/log1p_trans.Rd @@ -13,4 +13,3 @@ Log plus one transformation. trans_range(log_trans(), 1:10) trans_range(log1p_trans(), 0:9) } - diff --git a/man/log_breaks.Rd b/man/log_breaks.Rd index 6f4f946..de1294f 100644 --- a/man/log_breaks.Rd +++ b/man/log_breaks.Rd @@ -18,4 +18,3 @@ Log breaks (integer breaks on log-transformed scales). log_breaks()(c(1, 1e6)) log_breaks()(c(1, 1e5)) } - diff --git a/man/log_trans.Rd b/man/log_trans.Rd index be4c1fb..36769a3 100644 --- a/man/log_trans.Rd +++ b/man/log_trans.Rd @@ -1,9 +1,9 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/trans-numeric.r \name{log_trans} +\alias{log_trans} \alias{log10_trans} \alias{log2_trans} -\alias{log_trans} \title{Log transformation.} \usage{ log_trans(base = exp(1)) @@ -14,4 +14,3 @@ log_trans(base = exp(1)) \description{ Log transformation. } - diff --git a/man/manual_pal.Rd b/man/manual_pal.Rd index bae2f9b..884ade5 100644 --- a/man/manual_pal.Rd +++ b/man/manual_pal.Rd @@ -12,4 +12,3 @@ manual_pal(values) \description{ Manual palette (manual). } - diff --git a/man/math_format.Rd b/man/math_format.Rd index 5fec678..d8ccb28 100644 --- a/man/math_format.Rd +++ b/man/math_format.Rd @@ -31,4 +31,3 @@ math_format(format = percent)(runif(10)) \seealso{ \code{\link{plotmath}} } - diff --git a/man/muted.Rd b/man/muted.Rd index 9b67e66..04366b9 100644 --- a/man/muted.Rd +++ b/man/muted.Rd @@ -21,4 +21,3 @@ muted("red") muted("blue") show_col(c("red", "blue", muted("red"), muted("blue"))) } - diff --git a/man/ordinal_format.Rd b/man/ordinal_format.Rd index 8ad6648..918b868 100644 --- a/man/ordinal_format.Rd +++ b/man/ordinal_format.Rd @@ -1,8 +1,8 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/formatter.r \name{ordinal_format} -\alias{ordinal} \alias{ordinal_format} +\alias{ordinal} \title{Ordinal formatter: add ordinal suffixes (-st, -nd, -rd, -th) to numbers.} \usage{ ordinal_format(x) @@ -23,4 +23,3 @@ Ordinal formatter: add ordinal suffixes (-st, -nd, -rd, -th) to numbers. ordinal_format()(1:10) ordinal(1:10) } - diff --git a/man/package-scales.Rd b/man/package-scales.Rd index 7f8721c..c6bb4b8 100644 --- a/man/package-scales.Rd +++ b/man/package-scales.Rd @@ -3,10 +3,9 @@ \docType{package} \name{package-scales} \alias{package-scales} -\alias{package-scales-package} \alias{scales} +\alias{package-scales-package} \title{Generic plot scaling methods} \description{ Generic plot scaling methods } - diff --git a/man/parse_format.Rd b/man/parse_format.Rd index b343dcf..91a5d27 100644 --- a/man/parse_format.Rd +++ b/man/parse_format.Rd @@ -19,4 +19,3 @@ parse_format()(c("alpha", "beta", "gamma")) \seealso{ \code{\link{plotmath}} } - diff --git a/man/percent_format.Rd b/man/percent_format.Rd index 2e739f4..1669e8c 100644 --- a/man/percent_format.Rd +++ b/man/percent_format.Rd @@ -1,8 +1,8 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/formatter.r \name{percent_format} -\alias{percent} \alias{percent_format} +\alias{percent} \title{Percent formatter: multiply by one hundred and display percent sign.} \usage{ percent_format() @@ -24,4 +24,3 @@ percent_format()(runif(10)) percent(runif(10)) percent(runif(10, 1, 10)) } - diff --git a/man/pretty_breaks.Rd b/man/pretty_breaks.Rd index 913e200..780e433 100644 --- a/man/pretty_breaks.Rd +++ b/man/pretty_breaks.Rd @@ -22,4 +22,3 @@ pretty_breaks()(1:100) pretty_breaks()(as.Date(c("2008-01-01", "2009-01-01"))) pretty_breaks()(as.Date(c("2008-01-01", "2090-01-01"))) } - diff --git a/man/probability_trans.Rd b/man/probability_trans.Rd index 564808c..f37e820 100644 --- a/man/probability_trans.Rd +++ b/man/probability_trans.Rd @@ -1,8 +1,8 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/trans-numeric.r \name{probability_trans} -\alias{logit_trans} \alias{probability_trans} +\alias{logit_trans} \alias{probit_trans} \title{Probability transformation.} \usage{ @@ -18,4 +18,3 @@ function, and "q" + distribution is a valid quantile function.} \description{ Probability transformation. } - diff --git a/man/reciprocal_trans.Rd b/man/reciprocal_trans.Rd index fdca5d8..9075f7e 100644 --- a/man/reciprocal_trans.Rd +++ b/man/reciprocal_trans.Rd @@ -9,4 +9,3 @@ reciprocal_trans() \description{ Reciprocal transformation. } - diff --git a/man/regular_minor_breaks.Rd b/man/regular_minor_breaks.Rd new file mode 100644 index 0000000..c2e539a --- /dev/null +++ b/man/regular_minor_breaks.Rd @@ -0,0 +1,23 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/breaks.r +\name{regular_minor_breaks} +\alias{regular_minor_breaks} +\title{Minor breaks +Places minor breaks between major breaks.} +\usage{ +regular_minor_breaks(reverse = FALSE) +} +\arguments{ +\item{reverse}{if TRUE, calculates the minor breaks for a reversed scale} +} +\description{ +Minor breaks +Places minor breaks between major breaks. +} +\examples{ +m <- extended_breaks()(c(1, 10)) +regular_minor_breaks()(m, c(1, 10), n = 2) + +n <- extended_breaks()(c(0, -9)) +regular_minor_breaks(reverse = TRUE)(n, c(0, -9), n = 2) +} diff --git a/man/rescale.Rd b/man/rescale.Rd index f783038..b989110 100644 --- a/man/rescale.Rd +++ b/man/rescale.Rd @@ -2,20 +2,42 @@ % Please edit documentation in R/bounds.r \name{rescale} \alias{rescale} -\title{Rescale numeric vector to have specified minimum and maximum.} +\alias{rescale.numeric} +\alias{rescale.logical} +\alias{rescale.POSIXt} +\alias{rescale.Date} +\alias{rescale.integer64} +\title{Rescale continuous vector to have specified minimum and maximum.} \usage{ -rescale(x, to = c(0, 1), from = range(x, na.rm = TRUE, finite = TRUE)) +rescale(x, to, from, ...) + +\method{rescale}{numeric}(x, to = c(0, 1), from = range(x, na.rm = TRUE, + finite = TRUE), ...) + +\method{rescale}{logical}(x, to = c(0, 1), from = range(x, na.rm = TRUE, + finite = TRUE), ...) + +\method{rescale}{POSIXt}(x, to = c(0, 1), from = range(x, na.rm = TRUE, + finite = TRUE), ...) + +\method{rescale}{Date}(x, to = c(0, 1), from = range(x, na.rm = TRUE, finite + = TRUE), ...) + +\method{rescale}{integer64}(x, to = c(0, 1), from = range(x, na.rm = TRUE), + ...) } \arguments{ -\item{x}{numeric vector of values to manipulate.} +\item{x}{continuous vector of values to manipulate.} \item{to}{output range (numeric vector of length two)} -\item{from}{input range (numeric vector of length two). If not given, is +\item{from}{input range (vector of length two). If not given, is calculated from the range of \code{x}} + +\item{...}{other arguments passed on to methods} } \description{ -Rescale numeric vector to have specified minimum and maximum. +Rescale continuous vector to have specified minimum and maximum. } \examples{ rescale(1:100) @@ -23,4 +45,3 @@ rescale(runif(50)) rescale(1) } \keyword{manip} - diff --git a/man/rescale_max.Rd b/man/rescale_max.Rd index 9abb9d2..84b286d 100644 --- a/man/rescale_max.Rd +++ b/man/rescale_max.Rd @@ -22,4 +22,3 @@ rescale_max(1:100) rescale_max(runif(50)) rescale_max(1) } - diff --git a/man/rescale_mid.Rd b/man/rescale_mid.Rd index 7a6ef0b..febfe74 100644 --- a/man/rescale_mid.Rd +++ b/man/rescale_mid.Rd @@ -2,26 +2,47 @@ % Please edit documentation in R/bounds.r \name{rescale_mid} \alias{rescale_mid} -\title{Rescale numeric vector to have specified minimum, midpoint, and maximum.} +\alias{rescale_mid.numeric} +\alias{rescale_mid.logical} +\alias{rescale_mid.POSIXt} +\alias{rescale_mid.Date} +\alias{rescale_mid.integer64} +\title{Rescale vector to have specified minimum, midpoint, and maximum.} \usage{ -rescale_mid(x, to = c(0, 1), from = range(x, na.rm = TRUE), mid = 0) +rescale_mid(x, to, from, mid, ...) + +\method{rescale_mid}{numeric}(x, to = c(0, 1), from = range(x, na.rm = + TRUE), mid = 0, ...) + +\method{rescale_mid}{logical}(x, to = c(0, 1), from = range(x, na.rm = + TRUE), mid = 0, ...) + +\method{rescale_mid}{POSIXt}(x, to = c(0, 1), from = range(x, na.rm = TRUE), + mid, ...) + +\method{rescale_mid}{Date}(x, to = c(0, 1), from = range(x, na.rm = TRUE), + mid, ...) + +\method{rescale_mid}{integer64}(x, to = c(0, 1), from = range(x, na.rm = + TRUE), mid = 0, ...) } \arguments{ -\item{x}{numeric vector of values to manipulate.} +\item{x}{vector of values to manipulate.} \item{to}{output range (numeric vector of length two)} -\item{from}{input range (numeric vector of length two). If not given, is +\item{from}{input range (vector of length two). If not given, is calculated from the range of \code{x}} \item{mid}{mid-point of input range} + +\item{...}{other arguments passed on to methods} } \description{ -Rescale numeric vector to have specified minimum, midpoint, and maximum. +Rescale vector to have specified minimum, midpoint, and maximum. } \examples{ rescale_mid(1:100, mid = 50.5) rescale_mid(runif(50), mid = 0.5) rescale_mid(1) } - diff --git a/man/rescale_none.Rd b/man/rescale_none.Rd index 406edb8..49d897e 100644 --- a/man/rescale_none.Rd +++ b/man/rescale_none.Rd @@ -17,4 +17,3 @@ Don't peform rescaling \examples{ rescale_none(1:100) } - diff --git a/man/rescale_pal.Rd b/man/rescale_pal.Rd index 05a094d..7b3137d 100644 --- a/man/rescale_pal.Rd +++ b/man/rescale_pal.Rd @@ -14,4 +14,3 @@ values. Should be between 0 and 1.} Just rescales the input to the specific output range. Useful for alpha, size, and continuous position. } - diff --git a/man/reverse_trans.Rd b/man/reverse_trans.Rd index f15f4d8..6856403 100644 --- a/man/reverse_trans.Rd +++ b/man/reverse_trans.Rd @@ -9,4 +9,3 @@ reverse_trans() \description{ Reverse transformation. } - diff --git a/man/scientific_format.Rd b/man/scientific_format.Rd index 99eee55..e8a369b 100644 --- a/man/scientific_format.Rd +++ b/man/scientific_format.Rd @@ -1,8 +1,8 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/formatter.r \name{scientific_format} -\alias{scientific} \alias{scientific_format} +\alias{scientific} \title{Scientific formatter.} \usage{ scientific_format(digits = 3, ...) @@ -31,4 +31,3 @@ scientific(1:10) scientific(runif(10)) scientific(runif(10), digits = 2) } - diff --git a/man/seq_gradient_pal.Rd b/man/seq_gradient_pal.Rd index f11ffaa..fcba86d 100644 --- a/man/seq_gradient_pal.Rd +++ b/man/seq_gradient_pal.Rd @@ -26,4 +26,3 @@ show_col(seq_gradient_pal("white", "black")(x)) library(munsell) show_col(seq_gradient_pal("white", mnsl("10R 4/6"))(x)) } - diff --git a/man/shape_pal.Rd b/man/shape_pal.Rd index 0174750..188f3fd 100644 --- a/man/shape_pal.Rd +++ b/man/shape_pal.Rd @@ -12,4 +12,3 @@ shape_pal(solid = TRUE) \description{ Shape palette (discrete). } - diff --git a/man/show_col.Rd b/man/show_col.Rd index 953ff9d..45b0d3a 100644 --- a/man/show_col.Rd +++ b/man/show_col.Rd @@ -16,4 +16,3 @@ show_col(colours, labels = TRUE, borders = NULL) \description{ A quick and dirty way to show colours in a plot. } - diff --git a/man/sqrt_trans.Rd b/man/sqrt_trans.Rd index db34d36..ca27bd5 100644 --- a/man/sqrt_trans.Rd +++ b/man/sqrt_trans.Rd @@ -9,4 +9,3 @@ sqrt_trans() \description{ Square-root transformation. } - diff --git a/man/squish.Rd b/man/squish.Rd index 03bb577..ed76eaf 100644 --- a/man/squish.Rd +++ b/man/squish.Rd @@ -24,4 +24,3 @@ squish(c(-1, 0, 0.5, 1, 2)) \author{ Homer Strong <[email protected]> } - diff --git a/man/squish_infinite.Rd b/man/squish_infinite.Rd index 9841e08..d7f67ef 100644 --- a/man/squish_infinite.Rd +++ b/man/squish_infinite.Rd @@ -17,4 +17,3 @@ Squish infinite values to range. \examples{ squish_infinite(c(-Inf, -1, 0, 1, 2, Inf)) } - diff --git a/man/time_trans.Rd b/man/time_trans.Rd index d543b62..d2de6d2 100644 --- a/man/time_trans.Rd +++ b/man/time_trans.Rd @@ -20,4 +20,3 @@ t$transform(hours) t$inverse(t$transform(hours)) t$format(t$breaks(range(hours))) } - diff --git a/man/train_continuous.Rd b/man/train_continuous.Rd index 01d1a43..29a75df 100644 --- a/man/train_continuous.Rd +++ b/man/train_continuous.Rd @@ -14,4 +14,3 @@ train_continuous(new, existing = NULL) \description{ Train (update) a continuous scale } - diff --git a/man/train_discrete.Rd b/man/train_discrete.Rd index 4db24cc..fd8ea11 100644 --- a/man/train_discrete.Rd +++ b/man/train_discrete.Rd @@ -18,4 +18,3 @@ train_discrete(new, existing = NULL, drop = FALSE, na.rm = FALSE) \description{ Train (update) a discrete scale } - diff --git a/man/trans_breaks.Rd b/man/trans_breaks.Rd index 4c8b90a..6afa1ad 100644 --- a/man/trans_breaks.Rd +++ b/man/trans_breaks.Rd @@ -25,4 +25,3 @@ trans_breaks("sqrt", function(x) x ^ 2)(c(1, 100)) trans_breaks(function(x) 1 / x, function(x) 1 / x)(c(1, 100)) trans_breaks(function(x) -x, function(x) -x)(c(1, 100)) } - diff --git a/man/trans_format.Rd b/man/trans_format.Rd index 2392fdc..c2abf28 100644 --- a/man/trans_format.Rd +++ b/man/trans_format.Rd @@ -22,4 +22,3 @@ Format labels after transformation. tf <- trans_format("log10", scientific_format()) tf(10 ^ 1:6) } - diff --git a/man/trans_new.Rd b/man/trans_new.Rd index 00dd476..e9d6017 100644 --- a/man/trans_new.Rd +++ b/man/trans_new.Rd @@ -1,13 +1,14 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/trans.r \name{trans_new} -\alias{is.trans} -\alias{trans} \alias{trans_new} +\alias{trans} +\alias{is.trans} \title{Create a new transformation object.} \usage{ trans_new(name, transform, inverse, breaks = extended_breaks(), - format = format_format(), domain = c(-Inf, Inf)) + minor_breaks = regular_minor_breaks(), format = format_format(), + domain = c(-Inf, Inf)) } \arguments{ \item{name}{transformation name} @@ -21,6 +22,8 @@ inverse of the transformation} \item{breaks}{default breaks function for this transformation. The breaks function is applied to the raw data.} +\item{minor_breaks}{default minor breaks function for this transformation.} + \item{format}{default format for this transformation. The format is applied to breaks generated to the raw data.} @@ -38,4 +41,3 @@ the original scale. \seealso{ \Sexpr[results=rd,stage=build]{scales:::seealso_trans()} } - diff --git a/man/trans_range.Rd b/man/trans_range.Rd index 8a58809..1bd8ecc 100644 --- a/man/trans_range.Rd +++ b/man/trans_range.Rd @@ -15,4 +15,3 @@ given as a string.} \description{ Silently drops any ranges outside of the domain of \code{trans}. } - diff --git a/man/unit_format.Rd b/man/unit_format.Rd index 99336c4..102ce83 100644 --- a/man/unit_format.Rd +++ b/man/unit_format.Rd @@ -30,4 +30,3 @@ km(runif(10) * 1e5) \seealso{ \code{\link{comma}} } - diff --git a/man/viridis_pal.Rd b/man/viridis_pal.Rd new file mode 100644 index 0000000..391883b --- /dev/null +++ b/man/viridis_pal.Rd @@ -0,0 +1,36 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/pal-viridis.r +\name{viridis_pal} +\alias{viridis_pal} +\title{Viridis palette} +\usage{ +viridis_pal(alpha = 1, begin = 0, end = 1, direction = 1, + option = "D") +} +\arguments{ +\item{alpha}{The alpha transparency, a number in [0,1], see argument alpha in +\code{\link[grDevices]{hsv}}.} + +\item{begin}{The (corrected) hue in [0,1] at which the viridis colormap begins.} + +\item{end}{The (corrected) hue in [0,1] at which the viridis colormap ends.} + +\item{direction}{Sets the order of colors in the scale. If 1, the default, colors +are ordered from darkest to lightest. If -1, the order of colors is reversed.} + +\item{option}{A character string indicating the colormap option to use. Four +options are available: "magma" (or "A"), "inferno" (or "B"), "plasma" (or "C"), +and "viridis" (or "D", the default option).} +} +\description{ +Viridis palette +} +\examples{ +show_col(viridis_pal()(10)) +show_col(viridis_pal(direction = -1)(6)) +show_col(viridis_pal(begin = 0.2, end = 0.8)(4)) +show_col(viridis_pal(option = "plasma")(6)) +} +\references{ +\url{https://bids.github.io/colormap/} +} diff --git a/man/wrap_format.Rd b/man/wrap_format.Rd index aac65f9..28a4441 100644 --- a/man/wrap_format.Rd +++ b/man/wrap_format.Rd @@ -22,4 +22,3 @@ the width wrap_10 <- wrap_format(10) wrap_10('A long line that needs to be wrapped') } - diff --git a/man/zero_range.Rd b/man/zero_range.Rd index f980f0a..691b540 100644 --- a/man/zero_range.Rd +++ b/man/zero_range.Rd @@ -46,4 +46,3 @@ zero_range(c(-Inf, Inf)) # FALSE zero_range(c(Inf, Inf)) # TRUE } - diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index 6bd1492..1252b25 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -7,7 +7,7 @@ using namespace Rcpp; // doColorRamp StringVector doColorRamp(NumericMatrix colors, NumericVector x, bool alpha, std::string naColor); -RcppExport SEXP scales_doColorRamp(SEXP colorsSEXP, SEXP xSEXP, SEXP alphaSEXP, SEXP naColorSEXP) { +RcppExport SEXP _scales_doColorRamp(SEXP colorsSEXP, SEXP xSEXP, SEXP alphaSEXP, SEXP naColorSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; @@ -21,7 +21,7 @@ END_RCPP } // rgbToLab NumericVector rgbToLab(NumericVector rgb); -RcppExport SEXP scales_rgbToLab(SEXP rgbSEXP) { +RcppExport SEXP _scales_rgbToLab(SEXP rgbSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; @@ -32,7 +32,7 @@ END_RCPP } // rgbToXyz NumericVector rgbToXyz(NumericVector rgb); -RcppExport SEXP scales_rgbToXyz(SEXP rgbSEXP) { +RcppExport SEXP _scales_rgbToXyz(SEXP rgbSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; @@ -41,3 +41,15 @@ BEGIN_RCPP return rcpp_result_gen; END_RCPP } + +static const R_CallMethodDef CallEntries[] = { + {"_scales_doColorRamp", (DL_FUNC) &_scales_doColorRamp, 4}, + {"_scales_rgbToLab", (DL_FUNC) &_scales_rgbToLab, 1}, + {"_scales_rgbToXyz", (DL_FUNC) &_scales_rgbToXyz, 1}, + {NULL, NULL, 0} +}; + +RcppExport void R_init_scales(DllInfo *dll) { + R_registerRoutines(dll, NULL, CallEntries, NULL, NULL); + R_useDynamicSymbols(dll, FALSE); +} diff --git a/tests/testthat/test-bounds.r b/tests/testthat/test-bounds.r index aa3dd11..188f28b 100644 --- a/tests/testthat/test-bounds.r +++ b/tests/testthat/test-bounds.r @@ -2,34 +2,66 @@ context("Bounds") test_that("rescale_mid returns correct results", { x <- c(-1, 0, 1) - + expect_equal(rescale_mid(x), c(0, 0.5, 1)) expect_equal(rescale_mid(x, mid = -1), c(0.5, 0.75, 1)) expect_equal(rescale_mid(x, mid = 1), c(0, 0.25, 0.5)) - + expect_equal(rescale_mid(x, mid = 1, to = c(0, 10)), c(0, 2.5, 5)) - expect_equal(rescale_mid(x, mid = 1, to = c(8, 10)), c(8, 8.5, 9)) + expect_equal(rescale_mid(x, mid = 1, to = c(8, 10)), c(8, 8.5, 9)) }) -test_that("resacle_max returns correct results", { +test_that("rescale_max returns correct results", { expect_equal(rescale_max(0), NaN) expect_equal(rescale_max(1), 1) expect_equal(rescale_max(.3), 1) expect_equal(rescale_max(c(4, 5)), c(0.8, 1.0)) expect_equal(rescale_max(c(-3, 0, -1, 2)), c(-1.5, 0, -0.5, 1)) + expect_equal(rescale_max(c(-3, 0, -1, 2)), c(-1.5, 0, -0.5, 1)) }) test_that("zero range inputs return mid range", { expect_that(rescale(0), equals(0.5)) - expect_that(rescale(c(0, 0)), equals(c(0.5, 0.5))) + expect_that(rescale(c(0, 0)), equals(c(0.5, 0.5))) }) test_that("censor and squish ignore infinite values", { expect_equal(squish(c(1, Inf)), c(1, Inf)) expect_equal(censor(c(1, Inf)), c(1, Inf)) - - -}) \ No newline at end of file + + +}) + +test_that("scaling is possible with dates and times", { + dates <- as.Date(c("2010-01-01", "2010-01-03", "2010-01-05", "2010-01-07")) + expect_equal(rescale(dates, from = c(dates[1], dates[4])), seq(0,1,1/3)) + expect_equal(rescale_mid(dates, mid = dates[3])[3], 0.5) + + dates <- as.POSIXct(c("2010-01-01 01:40:40", + "2010-01-01 03:40:40", + "2010-01-01 05:40:40", + "2010-01-01 07:40:40")) + expect_equal(rescale(dates, from = c(dates[1], dates[4])), seq(0, 1, 1/3)) + expect_equal(rescale_mid(dates, mid = dates[3])[3], 0.5) + +}) + +test_that("scaling is possible with integer64 data", { + x <- bit64::as.integer64(2^60) + c(0:3) + expect_equal( + rescale_mid(x, mid = bit64::as.integer64(2^60) + 1), + c(0.25, 0.5, 0.75, 1)) +}) + +test_that("scaling is possible with NULL values", { + expect_null(rescale(NULL)) + expect_null(rescale_mid(NULL)) +}) + +test_that("scaling is possible with logical values", { + expect_equal(rescale(c(FALSE, TRUE)), c(0, 1)) + expect_equal(rescale_mid(c(FALSE, TRUE), mid = 0.5), c(0, 1)) +}) diff --git a/tests/testthat/test-breaks-minor.r b/tests/testthat/test-breaks-minor.r new file mode 100644 index 0000000..03611af --- /dev/null +++ b/tests/testthat/test-breaks-minor.r @@ -0,0 +1,17 @@ +context("minor breaks") + +l1 <- c(0, 9) +l2 <- -l1 +b1 <- extended_breaks()(l1) +b2 <- extended_breaks()(l2) +m1 <- regular_minor_breaks()(b1, l1, n = 2) +m2 <- regular_minor_breaks()(b2, l2, n = 2) + +test_that("minor breaks are calculated correctly", { + expect_equal(m1, seq(b1[1], b1[length(b1)], by = 1.25)) + expect_equal(m2, seq(b2[1], b2[length(b2)], by = 1.25)) +}) + +test_that("minor breaks for reversed scales are comparable to non-reversed", { + expect_equal(m1, sort(-m2)) +}) -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/r-cran-scales.git _______________________________________________ debian-med-commit mailing list [email protected] http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/debian-med-commit
