Comments (7)
I must say it is embarrassing that this bug happened in the first place but it is more embarrassing that it is not fixed. I nearly had a report going out with "NaN%" in there. Sorry, if this comes across angry, but it makes me sad when you can't rely on these easy things.
my.percent<- function(x) {
if(length(x)==1) if(x==0) return(paste0(0,"%") )
return(percent(x) )
}
from scales.
The problem ultimately arises because plyr:::round_any(0, 0)
return NaN
. (See https://github.com/hadley/plyr/blob/master/R/round-any.r#L28). I'm not sure what round_any
should return when accuracy == 0
; I'm thinking that it should just return x
unaltered. Or a vector of 0
the same length as x
.
# not real code because we are talking about a function in another package.
plyr:::round_any.numeric
function (x, accuracy, f = round)
{
if(accuracy == 0) {
x
} else {
f(x/accuracy) * accuracy
}
}
from scales.
I think that is a good solution. percent
similarly does not work for negative numbers and I submitted a pull request for that here: #40. It would be great to see both these changes made so that percent
works on all real numbers.
from scales.
@BrianDiggs I suspect there's a better rounding algorithm that will also work with small x. Hopefully twitter can help: http://twitter.com/hadleywickham/status/608679186597695488
from scales.
Any update on this?
The weird part is that it returns "0%" properly when passed in a vector with at least one no-zero value:
percent(c(0,2))
[1] "0%" "200%"
percent(0)
[1] "NaN%"
percent(c(0,0))
[1] "NaN%" "NaN%"
from scales.
IMO, the precision() function (which is used only by percent()) should be improved:
> precision(c(0.1, 100))
[1] 10
> precision(c(-0.1, 100))
[1] 100
> precision(0)
[1] 0
precision(0) should return 1 (this would fix the issue here), but for the other two I'm not sure.
from scales.
Could use mvpp's observation for a fix by creating a vector with dummy value and using only first numeric e.g.,
percent(c(0,1))[1]
bit of a dirty fix; but simple and works
from scales.
Related Issues (20)
- pseudo_log_trans does not respond to its base argument when in scale_*_continuous HOT 1
- Rescale with a vector of 0 HOT 1
- Upkeep for scales (2023)
- Feature request: `rescale.AsIs` method HOT 2
- Better breaks calculations for exponential transformations
- Suggestion: better documentation for format function options HOT 1
- Old page showing up in pkgdown display HOT 3
- Release scales 1.3.0
- Bug: where reversed global colour & fill aesthetic, and fixed colour in geom HOT 3
- scales: 2 issues
- `label_number` error when including `scale_cut` argument HOT 11
- Feature request: rescale transformation HOT 2
- Feature request: integer breaks
- feature requests: suppress trailing 0s when specifying accuracy and specify maximum number of digits when using NULL argument heuristic
- Add "real" ggplot examples to `label_*()` and `breaks_*()` functions
- Feature request: `label_log()` but for negative numbers
- Feature request: expand suite of colour manipulation functions
- Feature request: `pal_size`, `pal_alpha`, & `pal_linewidth` HOT 5
- Feature request: properties for palettes
- Feature request: `hold` argument for `label_*` functions HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from scales.