0

Following this example:

http://wiki.stdout.org/rcookbook/Graphs/Multiple%20graphs%20on%20one%20page%20(ggplot2)/

See the graph titled "Fitted growth curve per diet", I want to do the same thing but with a set of data that is in a CSV file such as (values are in µs, except for column "N"):

$ head RandomArray25PercentDup.csv 
N   SystemSort  QuickSort   RandomizedQuickSort TopDownMergeSort    BottomUpMergeSort   SelectionSort   InsertionSort   BubbleSort  
4   0   1   0   1   0   1   0   0   
5   0   0   0   1   1   0   1   0   
6   0   0   0   1   1   0   0   0   
7   0   0   0   0   1   0   0   0   
8   0   0   1   0   1   0   1   1   

...

I've tried this so far:

library(ggplot2)
library(reshape2)

data <- read.table("RandomArray25PercentDup.csv",
                   sep="\t",
                   header=TRUE)
data.m <- melt(data, id.vars = 1)

ggplot(data.m, aes(data, value, colour=variable)) +
    geom_point(alpha=.3) +
    geom_smooth(alpha=.2, size=1) +
    ggtitle("Random array with ~25% duplicate values")

My background in R is very limited, and I'm trying to learn using various ressources.

I have about 800'000 rows worth of data, with 20 repetitions in the measurement of each N (the reason why I want to see the scatter in transparent with a fitting curve for each algorithm).

1 Answer 1

2

Replacing this

data.m <- melt(data, id.vars = 1)

with

data.m <- melt(data, id.vars = "N")

and then

ggplot(data.m, aes(data, value, colour=variable)) +
    geom_point(alpha=.3) +
    geom_smooth(alpha=.2, size=1) +
    ggtitle("Random array with ~25% duplicate values")

with

ggplot(data.m, aes(N, value, colour=variable)) +
    geom_point(alpha=.3) +
    geom_smooth(alpha=.2, size=1) +
    ggtitle("Random array with ~25% duplicate values")

should do the trick. First replacement isn't really necessary, but it's always preferable to use variable names in case the order of the columns change. The first argument in aes is mapped to the x-axis. data is not a column so it can't be mapped.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.