Repository navigation
geom_spidergram (new) - #53
archaeothommy wants to merge 19 commits into
Conversation
Merge branch 'main' into geom-spidergram # Conflicts: # R/ASTR_geom_spider.R # R/ASTR_normalise_wrapper.R # man/geom_spider.Rd # man/normalise_data.Rd
|
I was not able to fix the "discrete values to continuous scale" problem other than the solution you suggested. I have no idea why this occurs. We create the The only difference I see is how the graphical elements are created; the coordinate transformation might be the issue. There are two differences in your approach compared to others:
And for whatever reason, the geom doesn't find the |
| normalise_geochem(df, reference = reference, ...) | ||
| }, | ||
| hundred = { | ||
| numeric_cols <- names(df)[sapply(df, is.numeric)] |
There was a problem hiding this comment.
This test should be moved to the normalisation function so that this function does not fail if it is called outside of the wrapper function.
| df[numeric_cols] <- normalise_rows(df[numeric_cols]) | ||
| df | ||
| }, | ||
| element = { |
There was a problem hiding this comment.
Please create a separate function for this normalisation. The wrapper is a convenience function and should not do anything else than dispatching it to functions that do the actual work.
| df[numeric_cols] <- lapply(df[numeric_cols], function(x) x / divisor) | ||
| df | ||
| }, | ||
| sample = { |
There was a problem hiding this comment.
Please create a separate function for this normalisation which is them called here. The wrapper is a convenience function and should not do anything else than dispatching it to functions that do the actual work.
| unknown = { | ||
| stop( | ||
| "Unknown reference '", reference, "'. ", | ||
| "`reference` must be one of: ", | ||
| "a geochemical reference composition (see `references_geochem`), ", | ||
| "a column name in `df`, ", | ||
| "an ID value in `df`, ", | ||
| "or '100%'." | ||
| ) | ||
| } |
There was a problem hiding this comment.
| unknown = { | |
| stop( | |
| "Unknown reference '", reference, "'. ", | |
| "`reference` must be one of: ", | |
| "a geochemical reference composition (see `references_geochem`), ", | |
| "a column name in `df`, ", | |
| "an ID value in `df`, ", | |
| "or '100%'." | |
| ) | |
| } | |
| stop( | |
| "Unknown reference '", reference, "'. ", | |
| "`reference` must be one of: ", | |
| "a geochemical reference composition (see `references_geochem`), ", | |
| "a column name in `df`, ", | |
| "an ID value in `df`, ", | |
| "or '100%'." | |
| ) |
The default function of switch statement is unnamed. It is automatically called in the input value does not match any other options.
|
|
@Abagna123 Could you let me know where the issue of log scale mismatch is happening? |
There was a problem hiding this comment.
@Abagna123 I I am having a build error for this.
'elements_data' is not an exported object from 'namespace:ASTR'
Why were these and other data sets modified?
There was a problem hiding this comment.
@karan3242 Nothing is missing or deleted. The data objects are internal by design. The build error comes from a single incorrect line in GeomSpider that uses ASTR::elements_data, which is not valid for internal package data.
optional_aes = c(ASTR::elements_data, ASTR::isotopes_data, ASTR::oxides_data),
- elements_data, isotopes_data, oxides_data, conversion_oxides are created in the data prep script (in data-raw/).
- They are saved with internal = FALSE, so they live in data/*.rda.
- They are documented in R/ASTR_data.R, but they are not exported (NAMESPACE has no export() lines for them).
That part was done by Thomas so I am confused, if they were never supposed to be exported, then ASTR:: should never have been used on them.
There was a problem hiding this comment.
Afaik exporting data does not work with the same @export -> NAMESPACE workflow as for functions. Hadley says "Never @export a data set.". But this also fails when you remove the ASTR::, which should usually work in functions inside a package. I think there is something weird about ggproto and when exactly it is evaluated.
After looking into this for a while I wonder if there even is a way to use this data here, if we want it to be available externally. Maybe the latter is not necessary? Then we could try the internal data setup lined out here: https://r-pkgs.org/data.html#sec-data-sysdata. Or we just have the data in there twice, internally and externally. A bit annoying, but this is an edge case.
|
@karan3242 library(ggplot2) test_df <- data.frame( elements <- c("La", "Ce", "Pr", "Nd", "Sm", "Eu", "Gd", "Tb", "Dy", "Ho", "Er", "Tm", "Yb", "Lu") 1. Raw values, linear scaleggplot(test_df) + 2. Chondrite normalised, log scaleggplot(test_df) + Test 1 and Test 2 are identical except for the y scale. Test 1 Lines plot correctly, y-axis shows normal values. Test 2 Y-axis shows 1e+25, 1e+42.... and even without y axis values when log_scale is applied . So i suspected geom_spider() creates the y values inside setup_data(). But ggplot2 applies the y-scale transform earlier in the build pipeline. So the transform runs before y exists. The axis then gets log labels while the data stays raw (e.g 1e+25, 1e+42). |
New approach to geom_spidergram(), allowing to supply a character vector of elements as aesthetic.
Previous code for data treatment is copied at the end of the file.