Darius
Darius

Reputation: 489

Forest graph using a dataframe already shaped

PROBLEM

I have a few datasets with data that have been already processed and exported with the following structure:

set.seed(123)
library(dplyr)
tb <- tibble(group = rep(c("A", "B"), each = 5),
             wkday = rep(c("Mon", "Tue", "Wed", "Thu", "Fri"), times = 2),
             sta = sample(-3:2, size = 10, replace = T),
             mid = sta + 2,
             fin = sta + 5)

QUESTION

I want to produce plots that look like the image below. How can I produce a plot like this one using ggplot, ggpubr or any other R packages? enter image description here

Upvotes: 1

Views: 186

Answers (1)

Nakx
Nakx

Reputation: 1600

This should get you started:

library(ggplot2)
ggplot(tb, aes(x=wkday, y= mid, ymin= sta, ymax=fin, lower = sta, upper = fin, middle = mid, fill= group)) +
  geom_boxplot(stat = "identity") +
  geom_hline(yintercept=0, linetype="dotted")+
  coord_flip()

enter image description here

Upvotes: 1

Related Questions