-2

I'm trying to use ggplot2 to create a line graph with factors and several dependent variables. The dataframe is structured like this:

Group Time DVName Mean SE

I'd like to produce a line graph in which x=Time, y=Mean, colour=DVName, and linetype=Group. When I try filling these in, however, I get odd results in which some of the datapoints are connected vertically rather than horizontally. I've also noticed that the order in which I input my dataset makes a difference in the look of the graph (sorting by Group produces a graph different from sorting by Time).

Any help out there?

Cheers! D

1 Answers1

0

Something like that ? Quite ugly with simulated data...

df <- data.frame(Group=factor(rep(1:3,20)),Time=runif(60),DVName=sample(c("a","b","c"), 60, rep=TRUE),Mean=rnorm(60))
ggplot(data=df) + geom_line(aes(x=Time, y=Mean, colour=DVName, linetype=Group))

enter image description here

juba
  • 47,631
  • 14
  • 113
  • 118
  • you might add this to get `df$Time <- df$Time[order(df$Time)]` and `df$Mean <- seq(1,60)` to get better plots, ( before the ggplot line of course) – agstudy Jan 25 '13 at 15:02
  • Yes -- that's it -- thanks juba. I was entering the aes after ggplot like this: ggplot(data=dataset, aes(x=Time, y= ...etc. What's the difference? I guess you have to pass the arguments directly to geom_line? – user2011285 Jan 25 '13 at 17:55
  • @user2011285 Well, on my system, both give the same result. – juba Jan 25 '13 at 19:20