0

I'm trying to make a simple line plot but I get the following error:

geom_path: Each group consist of only one observation. Do you need to adjust the group aesthetic?

I want status.std on the y-axis, effort on the x-axis, with status_measure distinguishing the two separate lines.

Below is my data and the code I'm executing:

df.effort <- structure(list(effort = structure(c(1L, 2L, 3L, 4L, 1L, 2L, 3L, 
4L), .Label = c("never", "not very hard", "hard enough", "very hard"
), class = "factor"), status.std = structure(c(-0.0234448237301297, 
0.0568346993679614, 0.0780165665285588, -0.0380394621882508, 
-0.135535917573711, 0.0128879641418037, 0.0806307867881565, -0.0104818763687783
), .Names = c("never", "not very hard", "hard enough", "very hard", 
"never", "not very hard", "hard enough", "very hard")), status_measure = structure(c(1L, 
1L, 1L, 1L, 2L, 2L, 2L, 2L), .Label = c("avrank.zmgs", "acent09l.zmgs"
), class = "factor")), .Names = c("effort", "status.std", "status_measure"
), row.names = c(NA, 8L), class = "data.frame")

ggplot(data=df.effort,
       aes(x=effort), y=status.std, colour=status_measure)) +   geom_line()

Many thanks for any help. I regret that this question seems unlikely to be instructive to others. If there is a title edit or something that would make it more general that would be fantastic.

2
  • 2
    Follow the instructions in the error message: add group=status_measure to your aes() call. (Also, you messed up the parentheses in your code, so as written, it won't run at all.) Commented Nov 30, 2012 at 22:01
  • 2
    Also y is defined outside of aes() it needs to be defined inside. I think all you need to do is remove the ) at the end of effort. Commented Nov 30, 2012 at 22:04

1 Answer 1

2

Syntax error. Need to move the paren so that aes(...) gets both the x and y arguments (but not the colour argument, because simply moving to the end generates the error you posted.)

ggplot(data=df.effort,
       aes(x=effort, y=status.std), colour=status_measure) +   geom_line()

Which succeeds but fails to color anything. And how could a color be picked for the lines anyway? I think the colors would adhere to the points, so try this:

ggplot(data=df.effort,  aes(x=effort, y=status.std))+ 
   geom_line()+ 
   geom_point(data=df.effort, 
       aes(x=effort, y=status.std, colour=status_measure))

Or maybe you do want what joran posted:

ggplot(data=df.effort,
   aes(x=effort, y=status.std, colour=status_measure, group=status_measure)) +
   geom_line()

(I thought you were trying to use geom_line to link measurements within category of effort with color distinguishing between status measures.)

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks to you and the others, +1 for all

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.