Ggplot2: 2 Horizontal Lines in Each Facet of A Facet-Grid And Not 3 Vatical Lines

Viewed 39

I want to join the 3 upper points in each face to be a horizontal line and the 3 lower points to be another horizontal line making 2 lines within a facet and not 3 vatical lines in a facet.

WHAT I HAVE

library(ggplot2)
library(reshape2)
set.seed(199)
MB_RMSE_sd1 <-  runif(12, min = 0, max = 2)
TMB_RMSE_sd1 <- runif(12, min = 0, max = 2)
MB_RMSE_sd3 <-  runif(12, min = 2, max = 5)
TMB_RMSE_sd3 <- runif(12, min = 2, max = 5)
MB_RMSE_sd5 <- runif(12, min = 5, max = 10)
TMB_RMSE_sd5 <- runif(12, min = 5, max = 10)
MB_RMSE_sd10 <-  runif(12, min = 7, max = 16)
TMB_RMSE_sd10 <- runif(12, min = 7, max = 16)

ID <- rep(rep(c("N10_AR0.8", "N10_AR0.9", "N10_AR0.95", "N15_AR0.8", "N15_AR0.9", "N15_AR0.95", "N20_AR0.8", "N20_AR0.9", "N20_AR0.95", "N25_AR0.8", "N25_AR0.9", "N25_AR0.95"), 1), 1)
df1 <- data.frame(ID, MB_RMSE_sd1, MB_RMSE_sd3, MB_RMSE_sd5, MB_RMSE_sd10, TMB_RMSE_sd1, TMB_RMSE_sd3, TMB_RMSE_sd5, TMB_RMSE_sd10)

reshapp1 <- reshape2::melt(df1, id = "ID")
reshapp1 <- unique(reshapp1)

NEWDAT <- data.frame(value = reshapp1$value, year = reshapp1$ID, n = rep(rep(c("10", "15", "20", "25"), each = 3), 8), Colour = rep(rep(c("RMSE_MB", "RMSE_TMB"), each = 3), 16), sd = rep(rep(c(1, 3, 5, 10), each = 24), 1),  phi = rep(rep(c("0.8", "0.9", "0.95"), 8), 4))

NEWDAT$sd <- with(NEWDAT, factor(sd, levels = sd, labels = paste("sd =", sd)))
NEWDAT$year <- factor(NEWDAT$year, levels = NEWDAT$year[1:12])
NEWDAT$n <- with(NEWDAT, factor(n, levels = n, labels = paste("n = ", n)))

ggplot(NEWDAT, aes(phi, value)) +
  geom_line(aes(linetype = Colour)) + geom_point() +
  scale_y_continuous(expand = c(0, 0), label = ~ abs(.)) +
  guides(fill = guide_legend(reverse = TRUE)) +
  facet_grid(sd ~ n, scales = "free") +
  theme_bw() +
  theme(axis.text.x = element_text(angle = -90, vjust = 0.5))

The Above R Code Produces This Facet-Grid

WHAT I WANT

The resemblance of the Output I Want

NOTE

I am comfortable with the pattern and not colour, I only use colour for my hand sketch.

0 Answers
Related