matrix.R 49.2 KB
Newer Older
Heraut Louis's avatar
Heraut Louis committed
                                annotate('text', x=Xr_mean[i],
                                         y=max(Y) + 0.63,
Heraut Louis's avatar
Heraut Louis committed
                                         label=unit_break,
Heraut Louis's avatar
Heraut Louis committed
                                         hjust=0.5, vjust=0.5, 
                                         size=2, color='grey40') +
                                # Writes the type of the breaking variable
                                annotate('text', x=Xr_mean[i],
                                         y=max(Y) + 0.9,
                                         label=paste("d", var, sep=''),
                                         hjust=0.5, vjust=0.5,
                                         size=3.25, color='grey20')
                        }
Heraut Louis's avatar
Heraut Louis committed
                    }

Heraut Louis's avatar
Heraut Louis committed
                    # For all the station on the page
                    for (k in 1:nsubCode) {
                        # Gets the code
                        code = subCode[k]
                        # Extracts label for the period dates
                        label = Periods_mean_per[Code_mean_per == code][1]
                        # Gets the start and end of the period
                        # for the station
                        periodStart = substr(label, 1, 4)
                        periodEnd = substr(label, 14, 17)

                        mat = mat +
                            # # Writes the starting value
                            annotate('text', x=Xc_mean, y=k + 0.13,
                                     label=bquote(bold(.(periodStart))),
                                     hjust=0.5, vjust=0.5, 
                                     size=3, color='grey40') + 
                            # Writes the ending value
                            annotate('text', x=Xc_mean, y=k - 0.13,
                                     label=bquote(bold(.(periodEnd))),
                                     hjust=0.5, vjust=0.5, 
                                     size=3, color='grey40')
                    }            
                }
                
                ### Code ###
                # For all the station
Heraut Louis's avatar
Heraut Louis committed
                for (k in 1:nsubCode) {
Heraut Louis's avatar
Heraut Louis committed
                    # Gets the code
Heraut Louis's avatar
Heraut Louis committed
                    code = subCode[k]
Heraut Louis's avatar
Heraut Louis committed
                    # Gets the name of the station
                    name = df_meta[df_meta$code == code,]$nom
                    # Fixes a limit for the max number
                    # of characters available
                    ncharMax = 38
                    # If the number of character of the name is greater
                    # than the limit
                    if (nchar(name) > ncharMax) {
                        # Cuts the name and add '...'
                        name = paste(substr(name, 1, ncharMax),
                                     '...', sep='')
                    }
Heraut Louis's avatar
Heraut Louis committed

                    mat = mat +
Heraut Louis's avatar
Heraut Louis committed
                        # Writes the code of the station
                        annotate('text', x=0.3, y=k + 0.14,
                                 label=bquote(bold(.(code))),
                                 hjust=1, vjust=0.5, 
                                 size=3.5, color="#00A3A8") +
                        # Writes the name of the station
                        annotate('text', x=0.3, y=k - 0.14,
                                 label=name,
                                 hjust=1, vjust=0.5, 
                                 size=3.5, color="#00A3A8")
Heraut Louis's avatar
Heraut Louis committed
                }

Heraut Louis's avatar
Heraut Louis committed
                ### Environment ###
Heraut Louis's avatar
Heraut Louis committed
                mat = mat +
Heraut Louis's avatar
Heraut Louis committed
                    # Fixed coordinate system
                    coord_fixed() +
                    # X axis
                    scale_x_continuous(limits=c(1 - rel(6), 
                                                width + rel(0.5)),
                                       expand=c(0, 0)) + 
                    # Y axis
                    scale_y_continuous(limits=c(1 - rel(0.5), 
                                                height + rel(2)),
                                       expand=c(0, 0))
                
                # Paper format in A3 if needed
                if (A3) {
                    width = 42
                    height = 29.7
                    dpi = 300
                    # Otherwise in A4
                } else {
                    width = 29.7
                    height = 21
                    dpi = 100
                }
Heraut Louis's avatar
Heraut Louis committed

Heraut Louis's avatar
Heraut Louis committed
                # Saving
                ggsave(plot=mat, 
                       path=outdirTmp,
                       filename=paste(outnameTmp,
                                      '_', type,
                                      '_', fL,
                                      iMat, sep=''),
                       device='pdf',
                       width=width, height=height,
                       units='cm', dpi=dpi)            
Heraut Louis's avatar
Heraut Louis committed
            }
Heraut Louis's avatar
Heraut Louis committed
        }           
    }
Heraut Louis's avatar
Heraut Louis committed
}