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.