0

So I have a data frame that looks something like this

Col1   Col2   Col3
------------------
foo    x11    y11
foo    x12    y12
foo    x13    y13
bar    x21    y21
bar    x22    y22
bar    x23    y23
baz    x31    y31
baz    x32    y32
baz    x33    y33

I'd like to plot one curve for each unique value in Column 1, and overlay them on the same plot, where the points on each curve are specified by the (numeric) (x, y) coordinates in Columns 2 and 3. I don't know what the values are in advance, and they don't have numeric labels. How can I do this?

(Believe it or not, I can't find the answer to this question anywhere on the Internet)

Thanks!

Jessica
  • 2,335
  • 2
  • 23
  • 36
  • What does "they don't have numeric labels" mean? You should post an example dataset. – IRTFM Nov 04 '14 at 20:31
  • @BondedDust it means the labels are things like "foo" and "bar" instead of 1, 2, 3 or Category1, Category2, Category3. This makes it less amenable to for loops and such. – Jessica Nov 04 '14 at 21:47

1 Answers1

0

Here are two possibilities, one with ggplot2 and one with base:

set.seed(1234)
df <- data.frame(fac = gl(3, 3), x = rep(1:3, 3), y = rnorm(9))

# ggplot
require(ggplot2)
ggplot(df, aes(x = x, y = y, col = fac)) +
  geom_line()

# base
dfwide <- reshape(df, timevar = 'fac', idvar = 'x', direction = 'wide')
matplot(dfwide[,-1], type = 'l')
EDi
  • 13,160
  • 2
  • 48
  • 57