The following works, it plots one column data based on the order of the data:
s<-data.frame(t=c(3, 50, 20, 100, 7, 80))
ggplot(s, aes(y=s$t, x=seq(1, length(s$t)))) +
geom_point()+
geom_hline(yintercept =10)
since I have many such data, I would like to put it in a function so that I can reuse it, as such:
plot1<-function(a, b, c){
ggplot(a, aes(y=a$b, x=seq(1, length(a$b)))) +
geom_point()+
geom_hline(yintercept =c)
}
However, the following does not work:
s<-data.frame(t=c(3, 50, 20, 100, 7, 80))
plot1(s, t, 10)
Instead, it produced this error message: Error: Aesthetics must be either length 1 or the same as the data (6): x, y
What went wrong?