Skip to content
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

Allow argument rotate_facet_labels in facet_geochem_gridh etc #8

Open
gavinsimpson opened this issue Nov 13, 2022 · 1 comment
Open

Comments

@gavinsimpson
Copy link

Labels for geochmical data can be long, as with species names, and being able to rotate the facet labels would be a useful addition. See for example:

library("pangaear")
library("tidyr")
library("tidypaleo")

doi <- "10.1594/PANGAEA.868790"
ara2b <- pg_data(doi)

ara2b_df <- ara2b[[1]]$data
ara2b_df

ara2b_l <- ara2b_df %>%
    pivot_longer(`TOC [%]`:`PDIP25`, names_to = "variable",
        values_to = "value")

ara2b_plot <- ara2b_l %>%
    ggplot(aes(x = value, y = `Age [ka BP]`)) +
    geom_lineh() +
    geom_point() +
    scale_y_reverse() +
    facet_geochem_gridh(vars(variable)) +
    labs(x = NULL, y = "Age [ka BP]")

ara2b_plot

which produces

tidypalaeo-issue

@paleolimbot
Copy link
Owner

I think you can do this with rotated_facet_labels() with more-or-less the same amount of code...I forget the details of why I made it an argument for the other facet type (I think something about interactions with other theme parameters):

library("pangaear")
#> Registered S3 method overwritten by 'httr':
#>   method           from  
#>   print.cache_info hoardr
library("tidyr")
library("ggplot2")
library("tidypaleo")

doi <- "10.1594/PANGAEA.868790"
ara2b <- pg_data(doi)
#> Downloading 1 datasets from 10.1594/PANGAEA.868790
#> Processing 1 files

ara2b_df <- ara2b[[1]]$data
ara2b_df
#> # A tibble: 110 × 15
#>    `Depth [m]` Age [ka…¹ TOC […² Brass…³ Brass…⁴ Dinos…⁵ Dinos…⁶ Campe…⁷ Campe…⁸
#>          <dbl>     <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>
#>  1        0        0        1.57   0.904    57.5   0.284   18.0    1.26     80.0
#>  2        0.05     0.164    1.44   0.711    49.4   0.402   27.9    0.865    60.1
#>  3        0.1      0.329    1.45   0.369    25.4   0.188   13.0    0.338    23.3
#>  4        0.15     0.493    1.33   0.359    27.0   0.179   13.5    0.341    25.7
#>  5        0.2      0.658    1.25   0.404    32.2   0.178   14.2    0.378    30.2
#>  6        0.25     0.822    1.24   0.632    50.9   0.338   27.2    0.543    43.7
#>  7        0.3      0.987    1.24   0.596    48.0   0.274   22.0    0.606    48.7
#>  8        0.35     1.15     1.21   0.515    42.6   0.277   22.9    0.5      41.4
#>  9        0.4      1.32     1.41   0.361    25.6   0.13     9.27   0.259    18.4
#> 10        0.45     1.48     1.24   0.298    24.0   0.103    8.31   0.244    19.7
#> # … with 100 more rows, 6 more variables: `β-Sitosterol/sed [µg/g]` <dbl>,
#> #   `β-Sitosterol/TOC [µg/g]` <dbl>, `IP25/sed [µg/g]` <dbl>,
#> #   `IP25/TOC [µg/g]` <dbl>, PBIP25 <dbl>, PDIP25 <dbl>, and abbreviated
#> #   variable names ¹​`Age [ka BP]`, ²​`TOC [%]`, ³​`Brassicasterol/sed [µg/g]`,
#> #   ⁴​`Brassicasterol/TOC [µg/g]`, ⁵​`Dinosterol/sed [µg/g]`,
#> #   ⁶​`Dinosterol/TOC [µg/g]`, ⁷​`Campesterol/sed [µg/g]`,
#> #   ⁸​`Campesterol/TOC [µg/g]`

ara2b_l <- ara2b_df %>%
  pivot_longer(`TOC [%]`:`PDIP25`, names_to = "variable",
               values_to = "value")

ara2b_plot <- ara2b_l %>%
  ggplot(aes(x = value, y = `Age [ka BP]`)) +
  geom_lineh() +
  geom_point() +
  scale_y_reverse() +
  facet_geochem_gridh(vars(variable)) +
  labs(x = NULL, y = "Age [ka BP]") +
  theme_paleo() +
  rotated_facet_labels()

ara2b_plot

Created on 2022-11-13 with reprex v2.0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants