0

Trying to plot the following data frame (call it bob):

1

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.

enter image description here

Not sure how to fix this problem, and have tried a couple of different things

2 Answers 2

1

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") 
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.