Current State:
I have two CSV files, their sample attached below:
FileOutputWithoutBuffer-Metrics.csv
File Length , Non-Buffered Time Taken (ns) 1000 , 5499114 2000 , 10971957 3000 , 15736008 4000 , 18970057 5000 , 22173215 6000 , 24612263 7000 , 26118520 8000 , 29934220 9000 , 31919477 10000 , 34940645
FileOutputWithBuffer-Metrics.csv
File Length , Buffered Time Taken (ns) 1000 , 412991 2000 , 224509 3000 , 269990 4000 , 461664 5000 , 485668 6000 , 479069 7000 , 413657 8000 , 438734 9000 , 760068 10000 , 576458
What I want:
I want to plot a compare and contrast graph between these two CSV files corresponding to their File Length
column.
What I did:
I wrote the below script for the same:
# This line has to be updated on every place, possible.
scriptPath <- "XXX/XXX/XXX/XXX";
# Read in all csv files.
FileOutputWithoutBufferMetrics <- read.csv(file = file.path(scriptPath, "FileOutputWithoutBuffer-Metrics.csv"), header = TRUE, sep = ",");
FileOutputWithBufferMetrics <- read.csv(file = file.path(scriptPath, "FileOutputWithBuffer-Metrics.csv"), header = TRUE, sep = ",");
FileOutputMetircs <- merge(FileOutputWithoutBufferMetrics, FileOutputWithBufferMetrics, by=c('File.Length'), all=T);
#colnames(FileOutputMetircs) <- c("File Length", "Non-Buffered OutputStream Time", "Buffered OutputStream Time");
show(FileOutputMetircs);
# Install extra packages :- ggplot2, reshape2.
list.of.packages <- c("ggplot2","reshape2");
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])];
if(length(new.packages)) {
install.packages(new.packages)
}
require(ggplot2);
require(reshape2);
# Create a graph of FileOutputStream.
df <- melt(FileOutputMetircs, id.vars = 'File.Length', variable.name = 'Time');
ggplot(df, aes(File.Length, value)) + geom_line(aes(colour = Time));
And got this output:
Where help is needed:
- First, since I am very new to ggplot. Therefore, need assurity on the correctness of my R script.
- Other ways (performace-wise) to optimize the script.
Thanks!.