I have the following data frame:
vector_builtin vector_loop vector_recursive
1 0.00 0.10 0.34
2 0.00 0.10 0.36
3 0.00 0.08 0.36
4 0.00 0.11 0.34
5 0.00 0.11 0.36
I want to display the three columns in a line chart.
I have imported ggplot2 into R and the chart is displaying without data or lines in it.
Code:
library(ggplot2)
indexes <- row.names(df.new)
ggplot(df.new, aes(x=vector_recursive, y=indexes))
Output I want A chart showing the three series in a line chart.
A very basic example using
ggplot2
and df from OP can be: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 usingdput
to provide the data to others, which will help troubleshoot your specific issue.However, you don't specify what your x axis is, so we will create a new variable that holds that information, for example:
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, butreshape2
'smelt
function could be used.Now when you correctly identify the names of the columns to plot,
ggplot2
will plot the data correctly: