Reputation: 1842
I'd like to use R to plot runtime results for function f
. At each datapoint on the x-axis, I run the simulation 10 times, I have 3 separate lines. At each datapoint, I'd like to also include the range with vertical lines illustrating the highest and lowest runtimes, while the data line goes through the point for the average value of each set of 10 results.
To make myself clearer, I have mocked up a plot that I am trying to describe:
I am not familiar with R, and so I am not sure how best I should save my dataset. This is what my data might look like for the solid line at the bottom:
------------------------------------------
| | Runs for solid line |
------------------------------------------
| Input | 1 | 2 | 3 | 4 | 5 |
------------------------------------------
| 2000 | 0.6 | 0.7 | 0.75 | 0.51 | 0.6 |
| 4000 | 0.9 | 1.0 | 1.1 | 0.8 | 0.7 |
| 6000 | 1.4 | 1.3 | 1.5 | 1.43 | 1.56 |
------------------------------------------
I can imagine two more tables: one for the dotted line, and one for the irregular dotted line. For the table above, I'd like a vertical line at 2000 indicating max=0.75, min=0.6, and the solid line to go through the mean value of 0.632 . The same for the regular and irregular dotted lines.
Upvotes: 2
Views: 4143
Reputation: 132736
I recommend reading an introduction to R.
Your data:
DF <- read.table(text="Input 1 2 3 4 5
2000 0.6 0.7 0.75 0.51 0.6
4000 0.9 1.0 1.1 0.8 0.7
6000 1.4 1.3 1.5 1.43 1.56",header=TRUE)
Let's reshape it to a more sensible format (long format):
library(reshape2)
DF <- melt(DF,id="Input")
Add an id for the line:
DF$group <- "a"
A second line:
DF2 <- DF
DF2$value <- DF2$value+1
DF2$group <- "b"
Put all data in one data.frame:
DF <- rbind(DF,DF2)
Now we can plot. There are numerous possibilities for plotting. Here is one that includes calculating the summary stats you want to plot:
library(ggplot2)
ggplot(DF,aes(x=Input,y=value,group=group)) +
stat_summary(fun.y="mean",geom="line",aes(linetype=group)) +
stat_summary(fun.ymin="min",fun.ymax="max",geom="errorbar")
Upvotes: 3