-1

I've set out a survey and logged the exact time people responded to the survey. I'm not exactly an R athlete nor a ggplot2 ninja, and I might have searched for the wrong terms.

I have response datetimes in the format %Y-%m-%d %H:%M:%S, e.g.: 2015-12-25 12:22:19, many of them, a couple of hundreds. And they range over a couple of weeks.

I have extracted them from my data frame, deleting NA value rows and single space value rows:

datetimes <- sort(t$survey_started_time[t$survey_started_time!=" "])
datetimes <- datetimes[complete.cases(datetimes)]

Then I made it a data frame and added index numbers:

df <-data.frame(datetimes)
df$id <- seq.int(nrow(df))

I now have this:

dput(head(df))

structure(list(datetimes = structure(2:7, .Label = c(" ", "2014-03-25 15:03:32", 
"2014-03-25 15:07:56", "2014-03-25 15:08:38", "2014-03-25 15:09:38", 
"2014-03-25 15:09:58", "2014-03-25 15:11:02", "2014-03-25 15:12:10", 
"2014-03-25 15:12:48", "2014-03-25 15:13:36", "2014-03-25 15:15:13", 
"2014-03-25 15:18:05", "2014-03-25 15:20:31", "2014-03-25 15:22:27", 
"2014-03-25 15:22:55", "2014-03-25 15:27:18", "2014-03-25 15:27:45", 
"2014-03-25 15:29:38", "2014-03-25 15:37:26", "2014-03-25 15:37:33", 
"2014-03-25 15:37:37", "2014-03-25 16:02:32", "2014-03-25 16:03:19", 
"2014-03-25 16:03:49", "2014-03-25 16:04:12", "2014-03-25 16:08:04", 
"2014-03-25 16:09:11", "2014-03-25 16:11:35", "2014-03-25 16:16:37", 
"2014-03-25 16:25:22", "2014-03-25 16:26:20", "2014-03-25 16:29:34", 
"2014-03-25 16:48:15", "2014-03-25 16:48:21", "2014-03-25 16:53:37", 
"2014-03-25 17:03:31", "2014-03-25 17:11:30", "2014-03-25 17:31:23", 
"2014-03-25 19:46:43", "2014-03-25 20:23:08", "2014-03-25 21:02:49", 
"2014-03-26 08:13:27", "2014-03-26 08:21:49", "2014-03-26 08:23:11", 
"2014-03-26 08:36:17", "2014-03-26 08:42:46", "2014-03-26 08:58:06", 
"2014-03-26 09:08:40", "2014-03-26 09:14:54", "2014-03-26 09:48:28", 
"2014-03-26 09:51:30", "2014-03-26 10:08:48", "2014-03-26 10:13:50", 
"2014-03-26 10:16:16", "2014-03-26 10:43:57", "2014-03-26 10:58:10", 
"2014-03-26 11:01:28", "2014-03-26 11:18:56", "2014-03-26 11:27:28", 
"2014-03-26 11:27:52", "2014-03-26 11:36:09", "2014-03-26 11:53:29", 
"2014-03-26 12:04:54", "2014-03-26 12:06:17", "2014-03-26 12:18:36", 
"2014-03-26 12:30:21", "2014-03-26 12:34:04", "2014-03-26 12:39:14", 
"2014-03-26 12:51:12", "2014-03-26 12:51:25", "2014-03-26 12:59:51", 
"2014-03-26 13:06:28", "2014-03-26 13:37:39", "2014-03-26 13:40:01", 
"2014-03-26 14:11:00", "2014-03-26 14:35:07", "2014-03-26 15:38:58", 
"2014-03-26 16:18:21", "2014-03-26 16:47:29", "2014-03-26 16:51:24", 
"2014-03-26 21:50:24", "2014-03-27 10:52:59", "2014-03-27 16:31:48", 
"2014-03-28 07:48:15", "2014-03-28 11:35:14", "2014-03-28 13:45:47", 
"2014-03-31 07:56:52", "2014-03-31 08:46:12", "2014-03-31 09:36:33", 
"2014-03-31 11:41:38", "2014-04-03 09:27:50", "2014-04-04 15:50:34", 
"2014-04-04 15:50:56", "2014-04-04 15:54:58", "2014-04-04 15:55:10", 
"2014-04-04 16:01:23", "2014-04-04 16:02:17", "2014-04-04 16:05:07", 
"2014-04-04 17:51:44", "2014-04-04 18:15:56", "2014-04-04 19:24:18", 
"2014-04-05 10:22:19", "2014-04-05 13:36:12", "2014-04-05 18:35:09", 
"2014-04-05 21:51:34", "2014-04-06 08:29:40", "2014-04-06 09:27:20", 
"2014-04-06 16:53:20", "2014-04-07 07:21:03", "2014-04-07 07:52:17", 
"2014-04-07 07:53:14", "2014-04-07 07:55:37", "2014-04-07 08:06:17", 
"2014-04-07 08:11:48", "2014-04-07 08:23:10", "2014-04-07 08:28:36", 
"2014-04-07 08:54:25", "2014-04-07 08:55:08", "2014-04-07 08:59:33", 
"2014-04-07 10:00:47", "2014-04-07 10:18:50", "2014-04-07 10:37:28", 
"2014-04-07 12:07:40", "2014-04-07 14:21:19", "2014-04-07 15:23:35", 
"2014-04-08 11:01:19", "2014-04-08 11:33:57", "2014-04-08 12:19:27", 
"2014-04-08 12:37:10", "2014-04-08 13:27:28", "2014-04-08 14:15:36", 
"2014-04-09 11:25:11", "2014-04-09 11:26:13", "2014-04-09 11:38:31", 
"2014-04-09 11:48:23", "2014-04-09 11:52:05", "2014-04-09 11:53:31", 
"2014-04-09 11:54:37", "2014-04-09 11:55:28", "2014-04-09 12:00:53", 
"2014-04-09 12:05:14", "2014-04-09 12:07:16", "2014-04-09 12:08:15", 
"2014-04-09 12:10:23", "2014-04-09 12:15:30", "2014-04-09 12:16:14", 
"2014-04-09 12:20:05", "2014-04-09 12:24:33", "2014-04-09 12:32:19", 
"2014-04-09 12:34:39", "2014-04-09 12:37:38", "2014-04-09 12:43:29", 
"2014-04-09 12:46:23", "2014-04-09 12:48:35", "2014-04-09 13:08:35", 
"2014-04-09 13:17:35", "2014-04-09 13:22:21", "2014-04-09 13:33:12", 
"2014-04-09 13:34:38", "2014-04-09 13:47:47", "2014-04-09 14:14:39", 
"2014-04-09 14:45:28", "2014-04-09 15:19:31", "2014-04-09 16:41:11", 
"2014-04-09 17:08:16", "2014-04-09 17:55:46", "2014-04-09 18:50:37", 
"2014-04-09 19:30:52", "2014-04-09 20:02:07", "2014-04-10 06:31:15", 
"2014-04-10 07:02:18", "2014-04-10 08:05:41", "2014-04-10 08:23:02", 
"2014-04-10 08:25:57", "2014-04-10 09:09:16", "2014-04-10 09:28:13", 
"2014-04-10 09:52:59", "2014-04-10 10:45:47", "2014-04-10 10:58:18", 
"2014-04-10 11:43:31", "2014-04-10 13:26:26", "2014-04-10 13:48:10", 
"2014-04-10 13:48:16", "2014-04-10 13:53:22", "2014-04-10 23:10:01", 
"2014-04-11 07:11:03", "2014-04-11 08:40:58", "2014-04-11 10:15:37", 
"2014-04-11 13:34:24", "2014-04-11 14:26:03", "2014-04-11 19:59:43", 
"2014-04-14 08:45:26", "2014-04-14 08:50:50", "2014-04-14 10:27:04", 
"2014-04-14 10:33:24", "2014-04-14 14:02:34", "2014-04-15 08:17:43", 
"2014-04-15 17:32:16"), class = "factor"), id = 1:6), .Names = c("datetimes", 
"id"), row.names = c(NA, 6L), class = "data.frame")

Now, I would like to plot in such way that dates are on the x-axis, and the indices on the y-axis.

Something like this, but then with only one line:

enter image description here

I tried:

ggplot(data=df, aes(x=datetimes, y=id))+ geom_line()

But that graph is having all the info somewhere at the bottom, and I receive the warning:

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

I would really appreciate it if someone could give me some hints the least.

Mickles
  • 13
  • 2
  • It's best when asking for plotting help to provide a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610) with sample input data to make it easier to help you. It sounds like you just need to sort and index them and then plot that. – MrFlick Jul 07 '15 at 21:45
  • Thanks for the links and the cues. I have adapted my question and added a sample of the data. – Mickles Jul 08 '15 at 14:20
  • Answer's on MrFlick! – Mickles Jul 08 '15 at 14:31

2 Answers2

0

I assume, by "slowly reach to" limit(eg 300) you mean you want one axis to be represented in logarithmic scale. Checkout scale_y_log10() and scale_x_log10() functions. Limits can be passed as parameters to these functions.

dF <- data.frame(values=sample(1:300,100))
dF$values <- sort(dF$values)
p <- ggplot(dF, aes(y=values,x=rownames(dF))) + geom_point() +     
     scale_x_discrete(breaks=NULL) + 
     scale_y_log10( limits = c(1,max(dF$values)) )
Onur
  • 317
  • 1
  • 2
  • 13
  • I'm sorry, but I'm not looking for a logarithmic scale, just the response-index line over time. – Mickles Jul 08 '15 at 14:19
0

Just make sure your datetimes column is an actual date/time value in R, not a character or factor. This should work:

df$dt<-strptime(df$datetimes, "%Y-%m-%d %H:%M:%S");
ggplot(data=df, aes(x=dt, y=id))+ geom_line()
MrFlick
  • 195,160
  • 17
  • 277
  • 295