简体   繁体   中英

How do I combine several comparisons between two groups in one graph using R?

I'm trying to compare two groups of patients. One group got drug A and the other got drug B. I have information of their blood pressure among other variables in 4 different time points: BB1, BB2, BB3 and BB4. I'd like to compare the groups at each time point using medians, 25th and 75th percenticles and show P-values for the differences between the groups.

Ideally I would like to have the two groups differentiated with say different colours and an offset between them, but with the time points presented on the same graph, perhaps with the medians connected by a line. That is to say, BB1 would be first shown for both groups, then BB2 etc.

For the life of me, I can't figure this out. Wise folks of the internet, please help me!

This is kinda getting there, but not really. https://community.rstudio.com/t/2-groups-multiple-variables/13151/3

This is an inelegant solution, but I did fix it.

library(tidyverse)
library(hrbrthemes)
library(viridis)

mmHg <- KetData$MAP1
MAP1Data <- data.frame(mmHg)
MAP1Data$Drug <- Data$Drug
MAP1Data$Time <- "1. timepoint"
mmHg <- KetData$MAP2
MAP2Data <- data.frame(mmHg)
MAP2Data$Drug <- Data$Drug
MAP2Data$Time <- "2. timepoint"

...

MAPData <- do.call("rbind", list(MAP1Data, MAP2Data, ...))

ggplot(MAPData, aes(x=Time, y=mmHg, fill=Drug)) +
  geom_boxplot() +
  scale_fill_viridis(discrete = TRUE, alpha=0.6) +
  geom_jitter(color="black", size=0.4, alpha=0.9) +
  theme_ipsum() +
  theme(
    legend.position="right",
    plot.title = element_text(size=11)
  ) +
  ggtitle("Mean arterial pressure at n timepoints") +
  xlab("")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM