0

I am working with data covering approximately 24 hours in 5 min increments.Click here for Dataset Click here for dput()

Obviously, plotting the following results in a congested x-axis:

 ggplot(df, aes(fill=cos,y=pctdrops, x=date))+
  geom_bar(position="dodge",stat="identity")+
  scale_x_datetime(date_breaks = "5 min",date_labels="%M")

ggplot(df, aes(fill=cos,y=pctdrops, x=date))+
  geom_bar(stat="identity")

To try and resolve the issue, I tried the following:

lims <- as.POSIXct(strptime(df$date,format = "%Y-%m-%d %H:%M"))

ggplot(data = df, 
       aes(x = date, y = pctdrops)) + 
  geom_line(size = 1.25) + 
  scale_x_datetime(labels = date_format("%H:%m"), 
                   breaks = date_breaks("5 min"), 
                   limits = lims,
                   expand = c(0, 0)) +
  theme_linedraw()

and receive "Error in zero_range(range) : x must be length 1 or 2"

I tried resolving this by adding:

scale_y_continuous(limits=c(0, 33.333), breaks=seq(0, 33.333, .556))

where y is the pctdrops 0% - 33.333% and increments by .556%

Code:

ggplot(data = df, 
       aes(x = date, y = pctdrops)) + 
  geom_line(size = 1.25) + 
  scale_x_datetime(labels = date_format("%H:%m"), 
                   breaks = date_breaks("5 min"), 
                   limits = lims,
                   expand = c(0, 0)) +
  scale_y_continuous(limits=c(0, 33.333), breaks=seq(0, 33.333, .556))
  theme_linedraw()

I still receive "Error in zero_range(range) : x must be length 1 or 2"

I am not sure if I am on the right track, but either way need help resolving the issue with the congested x-axis.

Leila
  • 11
  • 2
  • 2
    Can you share your data using `dput(df)`. See more here [How to make a great R reproducible example?](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – Tung May 22 '18 at 20:25
  • 1
    It must be me - but I don't really understand what you are trying to achieve... a desired output might help (me) – tjebo May 22 '18 at 22:11
  • 1
    Your file is really big and I'm not going to download it. Please instead `dput` a sample. But I don't understand why you've set the breaks to 5 minutes, if you don't want a label placed every 5 minutes. Maybe reread the docs for `scale_x_datetime`. A break of several hours is probably more appropriate – camille May 26 '18 at 16:29
  • @Camille - I am wanting a label placed every 5 minutes. I added a link to the dput() sample in the post – Leila May 30 '18 at 18:34
  • @Tung link to dput() added to post – Leila May 30 '18 at 18:39
  • @Tjebo - I am wanting to plot the pctdrops according to the timestamps - the issue is that there are 286 timestamps each associated with a pctdrop - the timestamps cover a 24 hour time period and incremented every 5 mins. I need to represent the 5 min breaks at associated pctdrop for each cos (class of service) in the plot – Leila May 30 '18 at 18:43
  • 2
    Please post `dput` directly into your question instead of a link. – acylam May 30 '18 at 19:57

0 Answers0