-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add units to ggplot #8
Comments
I will need some more context. What type of plot do you wish to be able to produce? Please provide some examples... |
We have implemented unit awareness in the units package and added support for plotting them in basic plots but not with ggplot. @edzer wrote about it here: http://r-spatial.org/r/2016/09/29/plot_units.html Essentially, we are just talking numbers with attributes that guarantee that units are converted when you multiply or divide them and that you cannot add or subtract units that can't be converted to each other. When plotting values with units we would love it if the labels would display the units together with the variables plotted. |
@thomasp85 what context do you need? We try to reproduce the last plot in the blog post @mailund mentions with the last command, as all information is in there. ggplot gives an error message (also in the blog) that indicates a comparison to a range, but ranges are also units:
or maybe this is the problem because the other argument got converted to numeric? I don't know how to use |
It was nicely explained in the post above - I just haven't had time to respond as I've just started on a new job... |
I'll try to give it some thought this evening - stay put |
I get Warning in R_ut_init: Can't open installed, default, unit database with both the CRAN and GitHub version on my mac every time I try to perform an operation with a unit vector... Does that ring any bell to either of you? |
Okay - I have looked into this a bit more. In terms of making sure that units are compatible: Do we agree that this is already handled since all data changes happens before being passed into ggplot? As I understand it we want to catch situations such as: ggplot(data, aes(x = var1 + var2, y = var3)) And throw errors when var1 and var2 are not compatible... This should already work. Now for the tough answer - we cannot make this automagical without a change to ggplot2 itself, meaning that if we want things to work after just adding e.g. What we can do without any change to ggplot2 is to add a ggplot(data, aes(x = var1 + var2, y = var3)) +
geom_point() +
scale_x_cunit("my axis title") will create an x-axis title as you want... I do think we should convince @hadley to accept a change though and I'll be happy to discuss my idea with him. In essence it requires an additional method to the scale class that allows scales to modify the default label. Please get back to me with your thoughts on this... |
I've opened a PR in ggplot2 with the required changes - I recommend we wait until these are resolved... |
Thanks for addressing this Thomas! Great to see this moving. Regarding the warning you see: it comes from |
I think it is more than an ignorable warning - when running the examples for |
Does it disappear when you do
first? |
I'll check when I get home and get back to you |
Loading Warning in R_ut_init: Can't open installed, default, unit database
Failed to load udunits2 system database: reading shipped version from /Library/Frameworks/R.framework/Versions/3.3/Resources/library/udunits2/share/udunits2.xml but removes the error when trying to do conversion... |
I've just pushed a fork that adds rudimentary units support. Please check it out and comment there (#15) |
Fixes #8 * Add units continuous scales * Add docs and fix small stuff
Using the units package we can associate (physical) units to quantities and guarantee that we only do arithmetic on compatible units. Plotting data with associated units, however, is cumbersome in ggplot. Can we make ggplot unit-aware?
The text was updated successfully, but these errors were encountered: