0

I am using the following code to draw plots:

lr_diab = read.table('/data/logistic_reg/log_diab.txt',sep='\t',header=TRUE)
(plot <- ggplot(lr_diab, aes(x = OR, y = Group)) + 
geom_vline(aes(xintercept = 1), linewidth = 0.25, linetype = "dashed") + 
geom_errorbarh(aes(xmax = CI_high, xmin = CI_low), size = .5, height = 
                 .2, color = "gray50") +
geom_point(size = 2.5, color = "orange") +
#coord_trans(x = scales:::exp_trans(10)) +
scale_x_continuous(breaks = (seq(0.2, 4.0, 0.2)), labels = seq(0.2, 4.0, 0.2),
                   limits = (c(0.5,4.0))) +
theme_bw()+
theme(panel.grid.minor = element_blank()) +
ylab("") +
xlab("Adjusted odds ratio") )

The lr_diab table or the log_diab file looks like this:

    Group   OR  CI_low  CI_high
    Pancreatic  2.74    2.39    3.15
    Liver   2.57    2.16    3.07
    Biliary tract   2.25    1.87    2.69
    Stomach 1.57    1.39    1.77
    Bladder 1.55    1.49    1.62
    Colorectal and anus 1.40    1.35    1.45
    Lung and trachea    1.37    1.29    1.46
    Prostate    1.33    1.29    1.37

I have 20 of these files and I need to draw 20 plots. All the header names are the same. Is there any way I can pass all the txt files names (like log_diab.txt) one by one and draw the plots for them using a loop?

Someone
  • 7
  • 2

0 Answers0