0

I'm working on a read.csv file, i need to create a lineplot with the following matrix:

Name   Day1   Day2   Day3  Day4.....

P1        1    1,1    1    0,99 
P2        2    2,1    2    2,21
P3        1,1  1,5    1,1  1,6
...       ...  ...    ...  ...

The line plot that i want to create has to be:

On the x axes the days ( name of the column)

On the y axes the values inside the matrix

And I need that from this graph will start one line for each product.

Gregor Thomas
  • 136,190
  • 20
  • 167
  • 294
Jua'
  • 51
  • 3
  • 9
  • 3
    Seems pretty similar: http://stackoverflow.com/questions/32254821/r-plot-multiple-columns-as-years-on-x-axis-plot-rows-as-different-lines/ – MrFlick May 02 '16 at 15:15

1 Answers1

0

Let df1 be you sstarting data, in order to plot the columns in x- axis you need them as values so you need to reshape the data

Code:

require(reshape)
df1<-data.frame(name=c("p1","p2","p3"),d1=c(1,2,3),d2=c(4,5,6),d3=c(7,8,9))
mdf1<-melt(df1) # melting
mdf1$ndays<-grep("[1:9]",mdf1$variable)
ggplot(data=mdf1,aes(x=ndays,y=value))+geom_path()
Gaurav Taneja
  • 1,084
  • 1
  • 8
  • 19