0

I am trying to show the limestone treatment amount of Ca on treatment sites (2,000 kg/ha) and I would like to remove the line from the Untreated site facet.

The code I have been using is:

soillimebudget %>% 
  mutate(`Stand Age` = factor(`Stand Age`, levels = c("NL", "14", "19", "23", "28", "32", "33", "37"))) %>% 
  mutate(`Treatment` = factor(`Treatment`, levels = c("Pre-Treatment Conditions", "Limestone, Stable", "Limestone, Eroded"))) %>%  mutate(Treatment = recode(Treatment, "Pre-Treatment Conditions" = "Untreated")) %>% 
  mutate(Pool = factor(Pool, levels = c("ABG", "LFH", "Mineral Soil"))) %>% 
  mutate(Pool = recode(Pool, "ABG" = "AGB")) %>% 
 group_by(Treatment, `Stand Age`, Pool) %>% 
  ggplot(aes(x = Mg, y = `Stand Age`, fill = `Pool`, position = "stack")) + 
  labs(title = "Mg Budget") + 
  labs(x = "Stand Age", y = "Mg (kg/ha)") +
  geom_bar(aes(`Stand Age`, `Mg`, fill = Pool), 
           position = "stack", stat = "identity") +
#scale_fill_grey(start = 0.3, end = 0.7) +
  theme_bw() +
geom_hline(linetype = "dashed", yintercept = 1000) +
  theme(legend.position =  "top") +
  theme(panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        panel.background = element_blank(),
        panel.border = element_rect(colour = "Black", fill = NA)) +
  theme(text = element_text(size = 30)) +
  facet_grid(~`Treatment`, scales = "free_x", space = "free_x")

Currently my figure is how I would like, barring removing the one H line from the Facet.

Thanks

  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input that can be used to test and verify possible solutions. – MrFlick Jun 22 '21 at 19:30

1 Answers1

0

Layers are facetted by the facetting variable in the data. To make geom_hline() appear in a subset of the facets, you'd need two things:

  1. (dummy) data that includes the facetting variables you need.
  2. A mapping created with aes(), otherwise the data -and thus facetting variables- are ignored.

Example with a standard dataset below:

library(ggplot2)

ggplot(iris, aes(Sepal.Width, Sepal.Length)) +
  geom_hline(
    data = data.frame(Species = c("setosa", "virginica"), y = 6),
    aes(yintercept = y)
  ) +
  geom_point() +
  facet_grid(~ Species)

Created on 2021-06-22 by the reprex package (v1.0.0)

teunbrand
  • 33,645
  • 4
  • 37
  • 63