diff --git a/02_Figures.R b/02_Figures.R index cee5870a65f46da0ac107dde4b84a68d29f240b9..a70509f9c5a11ba3cfc9fa4686331aceb5716d23 100644 --- a/02_Figures.R +++ b/02_Figures.R @@ -210,85 +210,6 @@ ggsave(filename="_pics/Fig3_TraitNumber.png", -#### test to duplicate rows in outp.summary and draw multiple lines next to each other -###create unique palette -gg_color_hue <- function(n) { - hues = seq(15, 375, length = n + 1) - hcl(h = hues, l = 65, c = 100)[1:n] -} -n = 5 ## 31 combination of traits -mycols = gg_color_hue(n) - -outp.summary2.multicolor <- outp.summary2 %>% - ungroup() %>% - uncount(as.numeric(as.character(sel.ntraits)), .id="replicate") %>% - group_by(ntraits, trait) %>% - ungroup() %>% - rowwise() %>% - mutate(which.traits=str_split(trait, pattern=" ")) %>% - mutate(trait.color=which.traits[replicate]) %>% - # left_join(data.frame(trait.color=c("t1", "t2", "t3", "t4", "t5"), - # color=mycols[1:5]), - # by="trait.color") %>% - #mutate(power=power + replicate/100) %>% - mutate(trait.repl = str_glue(as.character(trait)," r", replicate)) %>% - mutate(trait.repl = factor(trait.repl)) - -(fig3.multicolor <- ggplot(data=outp.summary2.multicolor) + - geom_line(aes(x=main, y=power, group=trait.repl, col=trait.color, lty=as.factor(replicate))) + - scale_x_continuous(name="Effect of factor e1 -> trait t1") + - scale_y_continuous(name="Power") + - #scale_colour_brewer(palette = "Dark2") + - facet_grid(sel.ntraits.lab~ntraits) + - theme_bw() + - theme(panel.grid = element_blank()) -) - - - - - -#### Alternative plotting to create grobs with individual legend -mydata <- outp.summary %>% - ungroup() %>% - rowwise() %>% - mutate(sel.ntraits=(get.ntraits(trait))) %>% - ungroup() %>% - dplyr::filter(stat.type=="XY") %>% - #filter(ntraits==3) %>% - #dplyr::filter(trait %in% c("1", "2", "1 2", "3")) %>% - #dplyr::filter(trait %in% c("1", "2", "3")) %>% - #dplyr::filter(trait %in% c("1", "2", "3", "1 2", "1 2 3")) %>% - mutate(ntraits=as.factor(ntraits)) %>% - mutate(sel.ntraits=as.factor(sel.ntraits)) - -gglist <- list() -tick <- 1 -for(sel in levels(mydata$sel.ntraits)){ - for(nn in levels(mydata$ntraits)){ - gglist[[tick]] <- ggplot(data=mydata %>% - filter(ntraits==nn) %>% - filter(sel.ntraits==sel)) + - geom_line(aes(x=main, y=power, group=trait, col=trait)) + - #scale_colour_brewer(palette = "Dark2") + - theme_bw() + - guides(fill=guide_legend(ncol=2)) + - theme(panel.grid = element_blank(), - legend.position = c(0.9,0.5), - legend.title = element_blank(), - legend.text = element_text(size=4), - legend.background = element_blank()) - tick <- tick + 1 - } -} -gglist[[1]] - -cowplot::plot_grid(plotlist=gglist, - nrow=5, ncol=3) - -ggsave(filename="_data/corXY_obs_Exp04March2020_TraitNumber.png", width=6, height=5, device="png", dpi = 300, last_plot()) - -