Trying to plot the following data frame (call it bob):
Since the original date is in d/m/y, I use Finaldate and Value to graph. Here is the code used to graph:
ggplot(Bob, aes(Finaldate, Value)) geom_line() geom_point(size = 3) labs(title = "TITLE",subtitle = "SUBTITLE", y = "Y", x = "X") theme_fivethirtyeight() scale_y_continuous(name="name", labels = scales::comma) theme(legend.title = element_blank()) scale_x_discrete(guide = guide_axis(check.overlap = TRUE))
While I do get an output, it is not as a time series but rather the dates are not in order and the plot makes no sense. Attached a copy of the plot as well.
Not sure how to fix this problem, and have tried a couple of different things
CodePudding user response:
Have you tried using
scale_x_date(date_labels = "%d %m %Y")
(ggplot2)
https://r-graph-gallery.com/279-plotting-time-series-with-ggplot2.html
CodePudding user response:
You need to convert Finaldate
to a date -- it is being treated as a character so all the dates are in "alphabetical" order. Try:
Bob$finalDate <- as.Date(Bob$finalDate, format = "%m/%d/%Y")