Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 1 | # Copyright 2017 Open Networking Foundation (ONF) |
| 2 | # |
| 3 | # Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>, |
| 4 | # the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>, |
| 5 | # or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg> |
| 6 | # |
| 7 | # TestON is free software: you can redistribute it and/or modify |
| 8 | # it under the terms of the GNU General Public License as published by |
| 9 | # the Free Software Foundation, either version 2 of the License, or |
| 10 | # (at your option) any later version. |
| 11 | # |
| 12 | # TestON is distributed in the hope that it will be useful, |
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | # GNU General Public License for more details. |
| 16 | # |
| 17 | # You should have received a copy of the GNU General Public License |
| 18 | # along with TestON. If not, see <http://www.gnu.org/licenses/>. |
| 19 | # |
| 20 | # If you have any questions, or if you don't understand R, |
Jeremy Ronquillo | b626884 | 2017-10-03 13:02:58 -0700 | [diff] [blame] | 21 | # please contact Jeremy Ronquillo: j_ronquillo@u.pacific.edu |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 22 | |
| 23 | # ********************************************************** |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 24 | # STEP 1: Data management. |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 25 | # ********************************************************** |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 26 | print( "**********************************************************" ) |
| 27 | print( "STEP 1: Data management." ) |
| 28 | print( "**********************************************************" ) |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 29 | has_flow_obj = 1 |
| 30 | database_host = 2 |
| 31 | database_port = 3 |
| 32 | database_u_id = 4 |
| 33 | database_pw = 5 |
| 34 | test_name = 6 |
| 35 | branch_name = 7 |
| 36 | batch_size = 8 |
| 37 | old_flow = 9 |
| 38 | save_directory = 10 |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 39 | |
Jeremy Ronquillo | b626884 | 2017-10-03 13:02:58 -0700 | [diff] [blame] | 40 | # Command line arguments are read. |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 41 | print( "Reading commmand-line args." ) |
| 42 | args <- commandArgs( trailingOnly=TRUE ) |
| 43 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 44 | # ---------------- |
| 45 | # Import Libraries |
| 46 | # ---------------- |
| 47 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 48 | print( "Importing libraries." ) |
| 49 | library( ggplot2 ) |
| 50 | library( reshape2 ) |
| 51 | library( RPostgreSQL ) # For databases |
| 52 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 53 | # ------------------- |
| 54 | # Check CLI Arguments |
| 55 | # ------------------- |
| 56 | |
| 57 | print( "Verifying CLI args." ) |
| 58 | |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 59 | if ( is.na( args[ save_directory ] ) ){ |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 60 | |
| 61 | print( paste( "Usage: Rscript SCPFIntentInstallWithdrawRerouteLat.R", |
| 62 | "<isFlowObj>" , |
| 63 | "<database-host>", |
| 64 | "<database-port>", |
| 65 | "<database-user-id>", |
| 66 | "<database-password>", |
| 67 | "<test-name>", |
| 68 | "<branch-name>", |
| 69 | "<batch-size>", |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 70 | "<using-old-flow>", |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 71 | "<directory-to-save-graphs>", |
| 72 | sep=" " ) ) |
Jeremy Ronquillo | 9ea85d0 | 2017-11-27 10:21:03 -0800 | [diff] [blame] | 73 | quit( status = 1 ) # basically exit(), but in R |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 74 | } |
| 75 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 76 | # ----------------------------------- |
| 77 | # Create File Name and Title of Graph |
| 78 | # ----------------------------------- |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 79 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 80 | print( "Creating filename and title of graph." ) |
| 81 | |
| 82 | chartTitle <- "Intent Install, Withdraw, & Reroute Latencies" |
| 83 | flowObjFileModifier <- "" |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 84 | errBarOutputFile <- paste( args[ save_directory ], |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 85 | "SCPFIntentInstallWithdrawRerouteLat_", |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 86 | args[ branch_name ], |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 87 | sep="" ) |
| 88 | |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 89 | if ( args[ has_flow_obj ] == "y" ){ |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 90 | errBarOutputFile <- paste( errBarOutputFile, "_fobj", sep="" ) |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 91 | flowObjFileModifier <- "fobj_" |
| 92 | chartTitle <- paste( chartTitle, "w/ FlowObj" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 93 | } |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 94 | if ( args[ old_flow ] == "y" ){ |
| 95 | errBarOutputFile <- paste( errBarOutputFile, "_OldFlow", sep="" ) |
| 96 | chartTitle <- paste( chartTitle, |
Devin Lim | 1bba762 | 2017-11-14 16:31:41 -0800 | [diff] [blame] | 97 | "With Eventually Consistent Flow Rule Store", |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 98 | sep="\n" ) |
| 99 | } |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 100 | errBarOutputFile <- paste( errBarOutputFile, |
| 101 | "_", |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 102 | args[ batch_size ], |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 103 | "-batchSize_graph.jpg", |
| 104 | sep="" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 105 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 106 | chartTitle <- paste( chartTitle, |
| 107 | "\nBatch Size =", |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 108 | args[ batch_size ], |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 109 | sep=" " ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 110 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 111 | # ------------------ |
| 112 | # SQL Initialization |
| 113 | # ------------------ |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 114 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 115 | print( "Initializing SQL" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 116 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 117 | con <- dbConnect( dbDriver( "PostgreSQL" ), |
| 118 | dbname = "onostest", |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 119 | host = args[ database_host ], |
| 120 | port = strtoi( args[ database_port ] ), |
| 121 | user = args[ database_u_id ], |
| 122 | password = args[ database_pw ] ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 123 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 124 | # --------------------------------------- |
| 125 | # Intent Install and Withdraw SQL Command |
| 126 | # --------------------------------------- |
| 127 | print( "Generating Intent Install and Withdraw SQL Command" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 128 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 129 | installWithdrawSQLCommand <- paste( "SELECT * FROM intent_latency_", |
| 130 | flowObjFileModifier, |
| 131 | "tests WHERE batch_size=", |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 132 | args[ batch_size ], |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 133 | " AND branch = '", |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 134 | args[ branch_name ], |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 135 | "' AND date IN ( SELECT MAX( date ) FROM intent_latency_", |
| 136 | flowObjFileModifier, |
| 137 | "tests WHERE branch='", |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 138 | args[ branch_name ], |
| 139 | "' AND ", |
| 140 | ( if( args[ old_flow ] == 'y' ) "" else "NOT " ) , |
| 141 | "is_old_flow", |
| 142 | ")", |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 143 | sep="" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 144 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 145 | print( "Sending Intent Install and Withdraw SQL command:" ) |
| 146 | print( installWithdrawSQLCommand ) |
| 147 | installWithdrawData <- dbGetQuery( con, installWithdrawSQLCommand ) |
| 148 | |
| 149 | # -------------------------- |
| 150 | # Intent Reroute SQL Command |
| 151 | # -------------------------- |
| 152 | |
| 153 | print( "Generating Intent Reroute SQL Command" ) |
| 154 | |
| 155 | rerouteSQLCommand <- paste( "SELECT * FROM intent_reroute_latency_", |
| 156 | flowObjFileModifier, |
| 157 | "tests WHERE batch_size=", |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 158 | args[ batch_size ], |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 159 | " AND branch = '", |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 160 | args[ branch_name ], |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 161 | "' AND date IN ( SELECT MAX( date ) FROM intent_reroute_latency_", |
| 162 | flowObjFileModifier, |
| 163 | "tests WHERE branch='", |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 164 | args[ branch_name ], |
| 165 | "' AND ", |
| 166 | ( if( args[ old_flow ] == 'y' ) "" else "NOT " ) , |
| 167 | "is_old_flow", |
| 168 | ")", |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 169 | sep="" ) |
| 170 | |
| 171 | print( "Sending Intent Reroute SQL command:" ) |
| 172 | print( rerouteSQLCommand ) |
| 173 | rerouteData <- dbGetQuery( con, rerouteSQLCommand ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 174 | |
| 175 | # ********************************************************** |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 176 | # STEP 2: Organize Data. |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 177 | # ********************************************************** |
| 178 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 179 | print( "**********************************************************" ) |
| 180 | print( "STEP 2: Organize Data." ) |
| 181 | print( "**********************************************************" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 182 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 183 | # ------------------------------------------------------- |
| 184 | # Combining Install, Withdraw, and Reroute Latencies Data |
| 185 | # ------------------------------------------------------- |
| 186 | |
| 187 | print( "Combining Install, Withdraw, and Reroute Latencies Data" ) |
| 188 | |
| 189 | if ( ncol( rerouteData ) == 0 ){ # Checks if rerouteData exists, so we can exclude it if necessary |
Jeremy Ronquillo | 9ea85d0 | 2017-11-27 10:21:03 -0800 | [diff] [blame] | 190 | |
| 191 | requiredColumns <- c( "install_avg", |
| 192 | "withdraw_avg" ) |
| 193 | |
| 194 | tryCatch( avgs <- c( installWithdrawData[ requiredColumns] ), |
| 195 | error = function( e ) { |
| 196 | print( "[ERROR] One or more expected columns are missing from the data. Please check that the data and SQL command are valid, then try again." ) |
| 197 | print( "Required columns: " ) |
| 198 | print( requiredColumns ) |
| 199 | print( "Actual columns: " ) |
| 200 | print( names( fileData ) ) |
| 201 | print( "Error dump:" ) |
| 202 | print( e ) |
| 203 | quit( status = 1 ) |
| 204 | } |
| 205 | ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 206 | } else{ |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 207 | colnames( rerouteData ) <- c( "date", |
| 208 | "name", |
| 209 | "date", |
| 210 | "branch", |
Devin Lim | 0e96716 | 2017-11-03 15:59:53 -0700 | [diff] [blame] | 211 | "is_old_flow", |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 212 | "commit", |
| 213 | "scale", |
| 214 | "batch_size", |
| 215 | "reroute_avg", |
| 216 | "reroute_std" ) |
| 217 | |
Jeremy Ronquillo | 9ea85d0 | 2017-11-27 10:21:03 -0800 | [diff] [blame] | 218 | tryCatch( avgs <- c( installWithdrawData[ 'install_avg' ], |
| 219 | installWithdrawData[ 'withdraw_avg' ], |
| 220 | rerouteData[ 'reroute_avg' ] ), |
| 221 | error = function( e ) { |
| 222 | print( "[ERROR] One or more expected columns are missing from the data. Please check that the data and SQL command are valid, then try again." ) |
| 223 | print( "Required columns: " ) |
| 224 | print( requiredColumns ) |
| 225 | print( "Actual columns: " ) |
| 226 | print( names( fileData ) ) |
| 227 | print( "Error dump:" ) |
| 228 | print( e ) |
| 229 | quit( status = 1 ) |
| 230 | } |
| 231 | ) |
| 232 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 233 | } |
| 234 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 235 | # Combine lists into data frames. |
| 236 | dataFrame <- melt( avgs ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 237 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 238 | # -------------------- |
| 239 | # Construct Data Frame |
| 240 | # -------------------- |
| 241 | |
| 242 | print( "Constructing data frame." ) |
| 243 | |
| 244 | if ( ncol( rerouteData ) == 0 ){ # Checks if rerouteData exists (due to batch size) for the dataFrame this time |
| 245 | dataFrame$scale <- c( installWithdrawData$scale, |
| 246 | installWithdrawData$scale ) |
| 247 | |
| 248 | dataFrame$stds <- c( installWithdrawData$install_std, |
| 249 | installWithdrawData$withdraw_std ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 250 | } else{ |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 251 | dataFrame$scale <- c( installWithdrawData$scale, |
| 252 | installWithdrawData$scale, |
| 253 | rerouteData$scale ) |
| 254 | |
| 255 | dataFrame$stds <- c( installWithdrawData$install_std, |
| 256 | installWithdrawData$withdraw_std, |
| 257 | rerouteData$reroute_std ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 258 | } |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 259 | |
| 260 | colnames( dataFrame ) <- c( "ms", |
| 261 | "type", |
| 262 | "scale", |
| 263 | "stds" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 264 | |
| 265 | # Format data frame so that the data is in the same order as it appeared in the file. |
| 266 | dataFrame$type <- as.character( dataFrame$type ) |
| 267 | dataFrame$type <- factor( dataFrame$type, levels=unique( dataFrame$type ) ) |
| 268 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 269 | dataFrame <- na.omit( dataFrame ) # Omit any data that doesn't exist |
Jeremy Ronquillo | 4363d09 | 2017-10-13 13:28:47 -0700 | [diff] [blame] | 270 | |
Jeremy Ronquillo | 2d2649d | 2017-09-14 12:53:06 -0700 | [diff] [blame] | 271 | print( "Data Frame Results:" ) |
| 272 | print( dataFrame ) |
| 273 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 274 | # ********************************************************** |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 275 | # STEP 3: Generate graph. |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 276 | # ********************************************************** |
| 277 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 278 | print( "**********************************************************" ) |
| 279 | print( "STEP 3: Generate Graph." ) |
| 280 | print( "**********************************************************" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 281 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 282 | # ------------------- |
| 283 | # Main Plot Generated |
| 284 | # ------------------- |
| 285 | |
| 286 | print( "Creating the main plot." ) |
| 287 | |
| 288 | mainPlot <- ggplot( data = dataFrame, aes( x = scale, |
| 289 | y = ms, |
| 290 | ymin = ms, |
| 291 | ymax = ms + stds, |
| 292 | fill = type ) ) |
| 293 | |
| 294 | # ------------------------------ |
| 295 | # Fundamental Variables Assigned |
| 296 | # ------------------------------ |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 297 | |
| 298 | print( "Generating fundamental graph data." ) |
| 299 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 300 | theme_set( theme_grey( base_size = 22 ) ) |
| 301 | barWidth <- 1.3 |
| 302 | xScaleConfig <- scale_x_continuous( breaks = c( 1, 3, 5, 7, 9) ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 303 | xLabel <- xlab( "Scale" ) |
| 304 | yLabel <- ylab( "Latency (ms)" ) |
| 305 | fillLabel <- labs( fill="Type" ) |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 306 | title <- ggtitle( chartTitle ) |
| 307 | imageWidth <- 15 |
| 308 | imageHeight <- 10 |
| 309 | imageDPI <- 200 |
| 310 | errorBarColor <- rgb( 140, 140, 140, maxColorValue=255 ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 311 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 312 | theme <- theme( plot.title=element_text( hjust = 0.5, size = 32, face='bold' ), |
| 313 | legend.position="bottom", |
| 314 | legend.text=element_text( size=22 ), |
| 315 | legend.title = element_blank(), |
| 316 | legend.key.size = unit( 1.5, 'lines' ) ) |
| 317 | |
| 318 | colors <- scale_fill_manual( values=c( "#F77670", |
| 319 | "#619DFA", |
| 320 | "#18BA48" ) ) |
Jeremy Ronquillo | 4363d09 | 2017-10-13 13:28:47 -0700 | [diff] [blame] | 321 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 322 | # Store plot configurations as 1 variable |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 323 | fundamentalGraphData <- mainPlot + |
| 324 | xScaleConfig + |
| 325 | xLabel + |
| 326 | yLabel + |
| 327 | fillLabel + |
| 328 | theme + |
| 329 | title + |
| 330 | colors |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 331 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 332 | # --------------------------- |
| 333 | # Generating Bar Graph Format |
| 334 | # --------------------------- |
| 335 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 336 | print( "Generating bar graph with error bars." ) |
Jeremy Ronquillo | 4363d09 | 2017-10-13 13:28:47 -0700 | [diff] [blame] | 337 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 338 | barGraphFormat <- geom_bar( stat = "identity", |
| 339 | width = barWidth, |
| 340 | position = "dodge" ) |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 341 | |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 342 | errorBarFormat <- geom_errorbar( width = barWidth, |
| 343 | position = position_dodge( barWidth ), |
| 344 | color = errorBarColor ) |
| 345 | |
| 346 | values <- geom_text( aes( x = dataFrame$scale, |
| 347 | y = dataFrame$ms + 0.035 * max( dataFrame$ms ), |
| 348 | label = format( dataFrame$ms, |
| 349 | digits = 3, |
| 350 | big.mark = ",", |
| 351 | scientific = FALSE ) ), |
| 352 | position = position_dodge( width = barWidth ), |
| 353 | size = 5.5, |
| 354 | fontface = "bold" ) |
| 355 | |
| 356 | wrapLegend <- guides( fill = guide_legend( nrow = 1, byrow = TRUE ) ) |
| 357 | |
| 358 | result <- fundamentalGraphData + |
| 359 | barGraphFormat + |
| 360 | errorBarFormat + |
| 361 | values + |
| 362 | wrapLegend |
| 363 | |
| 364 | # ----------------------- |
| 365 | # Exporting Graph to File |
| 366 | # ----------------------- |
| 367 | |
Jeremy Ronquillo | 6df8781 | 2017-08-28 16:17:36 +0000 | [diff] [blame] | 368 | print( paste( "Saving bar chart with error bars to", errBarOutputFile ) ) |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 369 | |
Jeremy Ronquillo | 9ea85d0 | 2017-11-27 10:21:03 -0800 | [diff] [blame] | 370 | tryCatch( ggsave( errBarOutputFile, |
| 371 | width = imageWidth, |
| 372 | height = imageHeight, |
| 373 | dpi = imageDPI ), |
| 374 | error = function( e ){ |
| 375 | print( "[ERROR] There was a problem saving the graph due to a graph formatting exception. Error dump:" ) |
| 376 | print( e ) |
| 377 | quit( status = 1 ) |
| 378 | } |
| 379 | ) |
Jeremy Ronquillo | 7673f80 | 2017-10-30 09:42:44 -0700 | [diff] [blame] | 380 | |
| 381 | print( paste( "[SUCCESS] Successfully wrote bar chart with error bars out to", errBarOutputFile ) ) |
Jeremy Ronquillo | 9ea85d0 | 2017-11-27 10:21:03 -0800 | [diff] [blame] | 382 | quit( status = 0 ) |