Issue
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]
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.
Answered By - Mohanasundaram Answer Checked By - Mildred Charles (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.