Plotting graph from Text file using R

1.3k Views Asked by At

I am using an NS3 based simulator called NDNsim. I can generate certain trace files that can be used to analyze performance, etc. However I need to visualize the data generated.

I am a complete Novice with R, and would like a way to visualize. Here is how the output looks from which I would to plot. Any help is appreciated.

2

There are 2 best solutions below

1
On BEST ANSWER

It's pretty difficult to know what you're looking for, since you have almost 50,000 measurements across 9 variables. Here's one way of getting a lot of that information on the screen:

df <- read.table(paste0("https://gist.githubusercontent.com/wuodland/",
                        "9b2c76650ea37459f869c59d5f5f76ea/raw/",
                        "6131919c105c95f8ba6967457663b9c37779756a/rate.txt"),
                 header = TRUE)

library(ggplot2)

ggplot(df, aes(x = Time, y = Kilobytes, color = Type)) + 
  geom_line() + 
  facet_wrap(~FaceDescr)

enter image description here

0
On

You could look into making sub structures from your input file and then graphing that by node, instead of trying to somehow invoke the plotter in just the right way.

df <- read.table(paste0("https://gist.githubusercontent.com/wuodland/",
                        "9b2c76650ea37459f869c59d5f5f76ea/raw/",
                        "6131919c105c95f8ba6967457663b9c37779756a/rate.txt"),
                 header = TRUE)

smaller_df <- df[which(df$Type=='InData'), names(df) %in% c("Time", "Node", 
                 "FaceId", "FaceDescr", "Type", "Packets", "Kilobytes",
                 "PacketRaw", "KilobyteRaw")]

ggplot(smaller_df, aes(x = Time, y = Kilobytes, color = Type)) 
       + geom_line() 
       + facet_wrap (~ Node)

The above snippet makes a smaller data frame from your original text data using only the "InData" Type, and then plots that by nodes.