第三年的大学生在这里,我有一个经济学项目可以在15日回去。我们必须与RMD合作,但我并不真正熟悉该工具...因此,任何帮助都将不胜感激!
我的问题是我想在多年来在比利时的GGPLOT上展示GDP的演变。这是我的数据的样子(您可以看到时间列与四分之一
ggplot(data = PIB, aes(x=PIB$Time, y=PIB$Belgium, group=1)) + geom_line() + labs(x="Time", y="Belgian PIB")
[
! ] [2]] [2]
我对图形的外观非常满意,除了X轴外观。 想显示在线4/5时间戳,因此读者可以理解演变从2001年到2021年,并且GDP每季度都会更改
该列的格式确实使我失望了。我 这可能是一个愚蠢的问题,但欢迎任何帮助!
[1]: https://i.sstatic.net/xvynw.png
[2]: https://i.sstatic.net/1f1ll.1f1ll.png
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.sstatic.net/XvYNW.png
[2]: https://i.sstatic.net/1f1Ll.png
发布评论
评论(2)
您必须将时间列从字符向量转换为时间。
然后尝试GGPLOT。
You have to convert the time column from a character vector to time.
Then try ggplot.
将时间转换为YearQtr类,并与
scale_x_yearqtr
一起使用。请参阅?scale_x_yearqtr
如果默认不是您想要的,请查看其各种参数。请注意 r 标记页面的信息特别是r问题应该提供文本输入,以便其他人可以将其复制并粘贴到他们的会话中。如果不将其全部重新播放,则不能轻易使用图像。在没有的情况下,我使用了末尾注释中显示的可重复输入。使用以下任何一个:
注释
Convert Time to yearqtr class and use with
scale_x_yearqtr
. See?scale_x_yearqtr
to review its various arguments if the default is not what you want.Note the information at the top of the r tag page and in particular R questions to SO should provide the input as text so that others can copy and paste it into their session. Images can't easily be used without retyping it all. In the absence of that I have used the reproducible input shown in the Note at the end. Use any of these:
Note