I ham fairly new to R and I might have a rather "stupid question" here.
I have a data frame that consists multiple measurements of 10 sensors (named X1,X2,...X10). Each row number indicates the the trial number. So for example if we assume we have 7 trials then the data frame looks something like this:
X1 X2 X3 X4 X5 X6 X7 X8 X9 X10
1 5 2 6 0 10 10 3 1 8 9
2 1 2 2 10 1 0 8 2 5 5
3 9 0 0 8 7 9 10 3 3 5
4 10 9 5 6 7 9 0 9 8 6
5 1 4 2 4 3 10 8 0 1 7
6 5 2 10 7 6 0 4 1 8 7
7 10 2 2 1 4 3 2 4 6 2
I want to plot all the rows together. For example for the first trial x will be 1:10 and y is the first row of the data frame.
I know some ways to do this but how can I use ggplot to do this ? Thanks
What you need to do is restructure the dataframe into a long format. There are many ways to do it. A quick one could be to use
reshape2
package e.g.Your data:
your dataframe now looks like this:
Then you can plot this
A scatter plot:
A line graph:
variable is your x-axis, value is your y-axis. I've made the variable 'rowid' a factor and we color by this factor also
Looks like this:
You can then play around with ggplot themes to make it look much nicer.