1

I have a dataframe that contains time(H:M:S), thetaX(degrees), thetaY(degrees), and thetaZ(degress). I want to plot the degrees vs time using ggplot as mentioned here.

This is the original state of my dataframe:

> head(df)
      time     thetaX       thetaY      thetaZ
1 08:27:27 0.01539380 -0.001609785 -0.03271715
2 08:27:27 0.03079389 -0.003863202 -0.06512209
3 08:27:27 0.04588598 -0.006668402 -0.09720450
4 08:27:28 0.06008822 -0.008774166 -0.12872514
5 08:27:28 0.07400642 -0.008951306 -0.15985775
6 08:27:28 0.08823425 -0.012280650 -0.19023676

I run these lines to plot each column of df over time:

df = data.frame(time, thetaX,thetaY,thetaZ)
> df.m = melt(df,id="time")
> ggplot(data = df.m, aes(x = x, y = value)) + geom_point() + facet_grid(variable ~ .)

But, this is what comes out: output

Question: Why is my data plotting from the what looks like the tail end at @1pm-ish of my df then jumping across to the beginning @8am-ish and finishing through the rest?

Kevin
  • 43
  • 2
  • 6
  • 5
    The order is determined by the values of the x-axis. I don't see any indication of "AM" or "PM" in your data, it looks like it's placing the 01 hour before the 08 hour, which makes good logical sense. Depending on the class of your `time` column it might be plotting in alphabetical order. Are you using a datetime class like `POSIXct`? – Gregor Thomas Aug 19 '17 at 00:07
  • Could you edit your question adding the out of `str(df)` ? – Marco Sandri Aug 19 '17 at 08:17

0 Answers0