Make sure that you have your data in a format that ggplot2
understands. In your code, geom_line
is expecting you to provide which columns in your data should correspond to which question. Below I have recreated your data, in the future, consider using dput
to provide the data to others, which will help troubleshoot your specific issue.
df=data.frame(vector_builtin=c(0.00,0.00,0.00,0.00,0.00),
vector_loop=c(0.10,0.10,0.08,0.11,0.11),
vector_recursive=c(0.34,0.36,0.36,0.34,0.36))
However, you don't specify what your x axis is, so we will create a new variable that holds that information, for example:
df$x=1:5
Now, I would recommend reshaping the data into long format, which is preferred by ggplot2
. You could also use the other answer here and specify each without that problem, but reshape2
's melt
function could be used.
library(reshape2)
df.m = melt(df, id.vars="x")
Now when you correctly identify the names of the columns to plot, ggplot2
will plot the data correctly:
ggplot() + geom_line(aes(color=variable, x=x, y=value), data=df.m)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…