-1

I am trying to plot 100 sheet of excel data that have different X and Y values. And, I am new to R, I just started using this a month ago. For now, I am trying to plot two sheets of data from the 100 sheets. I manage to use XLConnect to import the excel file onto R. And, string out the header from each sheets, so it doesn't mess up the format

And, I wrote this:

ggplot(data, aes(x,y)) + 
+     geom_line(data$Sheet1, aes(x=X, y=Y), colour = "blue")  
+     geom_line(data$Sheet100, aes(x=X, y=Y), colour = "red")

The R studio gives me this error message:

Error: ggplot2 doesn't know how to deal with data of class list

So in the end I tried data with header and without header. Eventually, both all have the same error problem. I don't know what to do. Could you please help me out?

Thanks

Update: the problem solved

p <- ggplot(data$Sheet1, aes(x=X,y=Y)) + geom_point(color='blue')
p
p <- p + geom_point(data= data$Sheet2,aes(x=X,y=Y),color='red')
p
p <- p + geom_point(data= data$Sheet3,aes(x=X,y=Y),color='pink') 
p

and continue adding for layering the plot

Karolis Koncevičius
  • 9,417
  • 9
  • 56
  • 89
kevla
  • 1
  • 1
  • 1
  • 2
  • You can provide a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). Until then, try combining your data into one data frame. You can `melt` or `unlist` lists to get them into data frames. Also the code you gave has double plus signs `+ +` that could cause errors. – oshun Jul 14 '15 at 18:05

1 Answers1

0

If data is a list then you have two issues. You should remove arguments from the ggplot call and then make sure you're explicit with the data argument in the geom_line calls. So, as a reproducible example:

x<-data.frame(a=1:10, b=1:10)
data<-list(sheet1=x,sheet2=x)
ggplot()+
  geom_line(data=data$sheet2, aes(a,b), size=3, color="red")+
  geom_line(data=data$sheet1, aes(a,b), color="yellow")
ZRoss
  • 1,437
  • 1
  • 15
  • 32
  • for the data.frame, I have data in x axis that goes from 0 to 15, and y axis goes from 0 to 100 range. So I put in this x <- data.frame(a=1:15, b=1:100) R seems have error on interpret these. – kevla Jul 14 '15 at 20:22