printing box plot in pdf inside a loop function

I have this code

pdf("~/BoxplotsToday.pdf")
for (i in unique(datanew$Trait)){ 
  print( datanew %>% 
    filter(between(value, 0, 2)) %>% filter(Marker %in% levels(datanew$Marker)) %>% 
    ggplot(aes(x= value, y = audpc, fill= value))+ geom_boxplot()+ 
    facet_wrap_paginate(~Marker, nrow=3, ncol = 5, page = i))
}
dev.off()

I want to save several box plots in a pdf but it is not working. Can someone please help me?

Can you provide minimal reproducible data associated with your code?

Here is the dataset, I joined several data together to get this.

Yet is ambiguous to track what you want to do. Please provide a minimal reproducible code with your sample data. Use reprexhttps://reprex.tidyverse.org/ package to achieve this. Or, else you can provide a link to access some sample data. Take an example down here for a reproducible case;

datanew <- data.frame( Marker = rep("u1", 5), 
                      value = c(rep(0, 2), rep(1, 3) ),
                      Traints = c( "Jul.10", "Aug.27", "Oct.01", "Jul.10", "Jan.25"),
                      audpc = c( 10.5, 131, 55, 150, 98) )
datanew
#>   Marker value Traints audpc
#> 1     u1     0  Jul.10  10.5
#> 2     u1     0  Aug.27 131.0
#> 3     u1     1  Oct.01  55.0
#> 4     u1     1  Jul.10 150.0
#> 5     u1     1  Jan.25  98.0

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.