R for making graphs - Waseda-Sato-lab/ccn-sim GitHub Wiki

R is a free software programming language and software environment for statistical computing and graphics. The R language is widely used among statisticians and data miners for developing statistical software and data analysis.

In this repository, we are trying to automate the way that we get information from our scenarios running on ns3 and we have decided to use R to manipulate our data. For the simulation execution automation, please refer to the "Bash scripts to run multiple scenarios" also available in this wiki.

Installing the basic R language

I will assume that you are using a Debian machine and that you have followed the instructions for installing the ndnSIM environment from the wiki. These instructions will differ if you are using a Debian clone (such as Ubuntu) but the essentials are the same. What we want is a R version greater than 3.x and a development environment.

The R packages included in Debian stable are 2.7.x and thus don't fulfill our requirements. Fortunately, the R users of CRAN have made it relatively simple to obtain a more up to date version of R for Debian.

The first thing we have to do is import the repository keys from CRAN. We can do this using root and typing in the following command:

# apt-key adv --keyserver keys.gnupg.net --recv-key 381BA480

Since we want to use apt-get to take care of our packages, we have to add the following line to /etc/apt/sources.list in our local filesystem:

deb http://cran.md.tsukuba.ac.jp/bin/linux/debian wheezy-cran3/

If you are unfamiliar with sources.list you can read through basic information here.

Once sources.list is updated, we can update our repository entries with the following command:

# apt-get update

Once finished, we can proceed to install R. The following command will install the minimum required packages:

# apt-get install r-base r-base-dev r-recommended r-mathlib libjpeg62

This completes the basic installation of R. From here on in if you type R in a terminal window, you should get output similar to the following:

$ R

R version 3.1.0 (2014-04-10) -- "Spring Dance"
Copyright (C) 2014 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

[Previously saved workspace restored]

>

Graphing packages

Although R has standard graphing capabilities, we have decided to use a few specialized packages. To install these, we will use R's internal package management. I recommend using root so that the packages are installed globally, but you can just as well use a normal user for these tasks. Just remember that if you install these packages as a normal user, the packages will only be available for that user!

First we go into R and then type, the following commands, one by one:

$ R
> install.packages('munsell')
> install.packages('scales')
> install.packages('ggplot2')
> install.packages('optparse')
> install.packages('doBy')

After each install.packages, the system will ask you to choose a CRAN mirror. Pick whichever one suits you. The install.packages command solves all the dependencies so once you finish the commands you will be able to use the R scripts in the repository without issue.

IDE

For those who are interested in developing in R and don't want to be using the terminal there are a couple of interesting IDEs for the language. An open-source choice is RStudio. For Debian machines you can download a deb package of the desktop version. The link is here.

At the time of writing the downloaded package is rstudio-0.98.507-amd64.deb. To install it you need to be root and run the following command in the directory the package downloaded:

# dpkg -i rstudio-0.98.507-amd64.deb

Once installed, the IDE can be run using the following command line:

$ rstudio

Running the R scripts

The R scripts in the repository make it easier to create graphs in an automated way. This section will try to explain how to use them.

l2-tr-j.R

This script graphs the ns3 level 2 drop rate. These files are of the type <scenario>-drop-trace-<networks>-<servers>-<clients>-<content size>.txt. The script uses Rscript, meaning that it can be used from the command line.

$ ./l2-tr-j.R -h
Usage: ./l2-tr-j.R [options]
Creates graphs from ndnSIM L2 Tracer data

Options:
        -p PRODUCERS, --producers=PRODUCERS
                Number of servers (producers) which will be displayed on
                the graph title.

        -c CLIENTS, --clients=CLIENTS
                Number of the clients (consumers) which will be displayed
                on the graph title.

        -s CONTENTSIZE, --contentsize=CONTENTSIZE
                Content size which will be displayed on the graph
                title. Input in bytes

        -n NETWORKS, --networks=NETWORKS
                Number of networks which will be displayed on the graph title.

        -f FILE, --file=FILE
                File which holds the raw drop data.
                [Default "results/drop-trace.txt"]

        -e NODE, --node=NODE
                Node data to graph. Default graphs all

        -h, --help
                Show this help message and exit

rate-tr-j.R

This script graphs the ns3 level 3 data rate. These files are of the type <scenario>-rate-trace-<networks>-<servers>-<clients>-<content size>.txt. The script uses Rscript, meaning that it can be used from the command line.

$ ./rate-tr-j.R -h
Usage: ./rate-tr-j.R [options]
Creates graphs from ndnSIM L3 Data rate Tracer data

Options:
        -p PRODUCERS, --producers=PRODUCERS
                Number of servers (producers) which will be displayed on
                the graph title.

        -c CLIENTS, --clients=CLIENTS
                Number of the clients (consumers) which will be displayed
                on the graph title.

        -s CONTENTSIZE, --contentsize=CONTENTSIZE
                Content size which will be displayed on the graph
                title. Input in bytes

        -n NETWORKS, --networks=NETWORKS
                Number of networks which will be displayed on the graph title.

        -f FILE, --file=FILE
                File which holds the raw drop data.
                [Default "results/rate-trace.txt"]

        -e NODE, --node=NODE
                Node data to graph. Default graphs all

        -t, --tcp
                Tell the script that the file contains TCP data

        -x, --ndn
                Tell the script that the file contains CCN data

        -h, --help
                Show this help message and exit
⚠️ **GitHub.com Fallback** ⚠️