I am a newbie to R and therefore this maybe "easy" for the R community. I have a data set with one x vector and serval (in this case 8) correspondig y vectors (matrix). I wanted to plot them in one graph with different line colors. Here is what I tried:
df = data.frame(x=x, y = matrix(nrow = length(x), ncol = 8))
mat=matrix(nrow = length(x), ncol = 8)
gp<-ggplot(df,aes(x,mat[,1], group_indices(mat))) +geom_line(size=1) +
xlab("Voltage") + ylab("Current") + scale_y_log10() + ggtitle(paste("IV Curve") )
for (i in seq(2,8,1) )
{
gp= gp + geom_line(aes(x,y=mat[,i], colour=i),size=1)
}
But this give me only the first and last data in one graph.
What works is this:
gp= gp + geom_line(aes(x,mat[,2], colour=2),size=1) +
geom_line(aes(x,mat[,3], colour=3),size=1) +
geom_line(aes(x,mat[,4], colour=4),size=1) +
geom_line(aes(x,mat[,5], colour=5),size=1) +
geom_line(aes(x,mat[,6], colour=6),size=1) +
geom_line(aes(x,mat[,7], colour=7),size=1) +
geom_line(aes(x,mat[,8], colour=8),size=1)
But I want to do it more automatic and simple. I am open for new ideas and I guess I am not good with the different variable types in R. Thanks in advance.