Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I simplify the X-axis scale (year Quarters R)

3rd year uni student here, I have an econometry project to hand back on the 15th; we have to work with Rmd but I’m not really familiar with the tool… so any help would be much appreciated!
My problem here is that I want to display on a ggplot the evolution of GDP in Belgium throughout the years. Here’s what my data looks like (you can see the Time column is organized with quarters [![Data to work with][1]][1]. I coded this:

ggplot(data = PIB, aes(x=PIB$Time, y=PIB$Belgium, group=1))  + geom_line() + labs(x="Time", y="Belgian PIB")

and here’s the ouput I have:

[![ggplot evolution graph][2]][2]

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I’m very satisfied with how the graph looks except for the X-axis. I looked online on many platforms but I can’t for the life of me figure out how to organize the Time axis. The format of the column really throws me off.. I’d like for online 4/5 timestamps to be shown, so the reader can understand that the evolution goes from 2001 to 2021 and that the GDP changes every quarter.

I’m aware this is probably a stupid question but any help would be welcome!
[1]: https://i.stack.imgur.com/XvYNW.png
[2]: https://i.stack.imgur.com/1f1Ll.png

>Solution :

You have to convert the time column from a character vector to time.

library(zoo)
PIB$Time = as.yearqtr(PIB$Time,format="%YQ%q")
PIB$Time = as.Date(PIB$Time)

Then try ggplot.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading