ggplot2 slope chart of before/after
I'm not skilled enough with ggplot2, but it seems the best library to create a slope chart to represent my results graphically. I have to represent a slope chart pointing to the differences in the results before and after the treatment. Be aware, I need to show that the two treatments produced almost the same results; that's why I'm looking for this chart. Thank you.
id<-c(1:5)
after<-c(35.69, 38.96, 33.10, 27.11, 36.55)
before<-c(35.96, 39.70, 33.85, 27.92, 38.38)
df<-data.frame(id, after,before)
Is this what you are after?
df <- data.frame(id, after,before) %>%
pivot_longer(cols = c("after", "before"),
names_to = "time")
ggplot(data = df,
aes(x = time,
y = value,
group = id,
color = factor(id))) +
geom_line(size = 2,
alpha = 0.5) +
geom_point(size = 3)