Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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)

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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)

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading