I'm trying to create a loop in ggplot as follows:
LEDnum = c(1,2,3,4,5)
for (i in 1:length(LEDnum))
{
ggplot(LEDref,aes(x=sample1))+
geom_line(aes(y=assign(paste("LEDrefLED",LEDnum[i],sep="")))) +
ggtitle(paste("LED ref + LED ",LEDnum[i],sep=""))
}
I have already existing objects (numeric lists) named LEDrefLED1,LEDrefLED2, etc. However, when I run this code it doesn't recognise the geom_line data as being my existing variable. I assume this is because paste() creates a character string but as I am new to R I don't know how to make it recognise it as the preexisting object.