Skip to content

Instantly share code, notes, and snippets.

@maurolepore
Last active April 30, 2018 21:10
Show Gist options
  • Save maurolepore/fece90d9ee43f521322b12addd1de0ae to your computer and use it in GitHub Desktop.
Save maurolepore/fece90d9ee43f521322b12addd1de0ae to your computer and use it in GitHub Desktop.
Aspect plots for Stuart Davies
library(tidyverse)

aspect <- tribble(
       ~aspect, ~mean,  ~min, ~max,
      "Valley",  3.21,  1.93, 4.41,
       "Slope", -0.24, -1.78, 1.22,
  "High Gully",  0.32, -3.47, 2.95,
       "Ridge", -2.47, -8.85, 2.61
)
aspect
#> # A tibble: 4 x 4
#>   aspect      mean   min   max
#>   <chr>      <dbl> <dbl> <dbl>
#> 1 Valley      3.21  1.93  4.41
#> 2 Slope      -0.24 -1.78  1.22
#> 3 High Gully  0.32 -3.47  2.95
#> 4 Ridge      -2.47 -8.85  2.61

ordered <- c(
  "Ridge",
  "Slope", 
  "High Gully", 
  "Valley" 
)
aspect$aspect <- factor(aspect$aspect, levels = ordered)

ggplot(aspect, aes(aspect, mean)) +
  geom_col(width = 0.5) + 
  geom_errorbar(aes(ymin = min, ymax = max), width = 0.1) +
  geom_hline(yintercept = 0) +
  theme_classic() +
  ylab("AGB Change (Mg/ha/yr)") +
  xlab("") +
  coord_cartesian(ylim = c(-5, 5))

Created on 2018-04-30 by the reprex package (v0.2.0).

@maurolepore
Copy link
Author

library(tidyverse)

aspel <- read_csv("http://bit.ly/2Kr6Qv5")
#> Parsed with column specification:
#> cols(
#>   aspect = col_character(),
#>   element = col_character(),
#>   mean = col_double(),
#>   se = col_double()
#> )

ordered <- c(
  "Ridge",
  "Slope", 
  "High Gully", 
  "Valley" 
)
aspel$aspect <- factor(aspel$aspect, levels = ordered)
aspel$element <- factor(aspel$element, levels = c("Mg", "Ca", "Bray P"))

ggplot(aspel, aes(aspect, mean)) +
  geom_errorbar(aes(ymin = mean - se, ymax = mean + se), width = 0.2) +
  geom_point() +
  facet_grid(element ~ ., scales = "free_y") +
  theme_bw() +
  ylab("") +
  xlab("")

Created on 2018-04-30 by the reprex package (v0.2.0).

@maurolepore
Copy link
Author

library(tidyverse)

url <- "http://bit.ly/2vXP7bp"
agb <- read_csv(url)
#> Parsed with column specification:
#> cols(
#>   aspect = col_character(),
#>   mean = col_double(),
#>   min = col_double(),
#>   max = col_double()
#> )

ordered <- c(
  "Ridge",
  "Slope", 
  "High Gully", 
  "Valley" 
)
agb$aspect <- factor(agb$aspect, levels = ordered)

ggplot(agb, aes(aspect, mean)) +
  geom_col(width = 0.5) + 
  geom_errorbar(aes(ymin = min, ymax = max), width = 0.1) +
  theme_classic() +
  ylab("AGB") +
  xlab("")

Created on 2018-04-30 by the reprex package (v0.2.0).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment