简体   繁体   English

更改R中Y轴上的中断(时间序列)

[英]Changing Breaks on Y Axis in R (Time series)

I've a dataset showing house prices for a variety of different cities over a period of 19 years, here's what it looks like. 我有一个数据集,显示了19年内各种城市的房价,这是它的样子。

Dataset 数据集

I'm trying to create a time series plot for this data, this is my code so far 我正在尝试为此数据创建时间序列图,这是到目前为止的代码

    Prices <- read.csv("Second Hand Appartment Prices.csv", header=TRUE, skip = 1)
colnames(Prices)[colnames(Prices)=="X"] <- "Year"



National <- ts(Prices$National, start = 1997)
Dublin <- ts(Prices$Dublin, start = 1997)
Cork <- ts(Prices$Cork, start = 1997)
Galway <- ts(Prices$Galway, start = 1997)
Limerick <- ts(Prices$Limerick, start = 1997)
Waterford <- ts(Prices$Waterford, start = 1997)
OtherAreas <- ts(Prices$Other.Areas, start = 1997)
color <- rainbow(ncol(Prices))
ts1 <- ts.plot(National, Dublin, Cork, Galway, Limerick, Waterford, OtherAreas, xlab = "Years", ylab ="Average Price", main = "Second Hand Appartment Prices 1997-2005", col = color)
legend("bottom", legend = colnames(Prices), lty=1, col = color,cex=0.5)

I'm trying to change the time series plot so the breaks are eg 0,50000,100000, etc etc 我正在尝试更改时间序列图,因此中断时间为例如0,50000,100000等

Can anyone help me on this? 谁可以帮我这个事? Much appreciated 非常感激

I can only use base R graphics for this as that is specified in the assignment 我只能使用作业中指定的基本R图形

Here is what my code is producing currently 这是我的代码当前正在生成的

Time series plot 时间序列图

You may try 你可以试试

ts.plot(National, Dublin, Cork, Galway, Limerick, Waterford, OtherAreas, 
        gpars = list(yaxt = 'n'))
axis(side = 2, 
     at = seq(from = 0, to = max(Prices[, colnames(Prices) != 'Year']), by = 50000), 
     labels = seq(from = 0, to = max(Prices), by = 50000))

The argument yaxt='n' suppress the ticks on the y-axis. 参数yaxt='n'抑制y轴上的刻度。 Then function axis() then draw the ticks you want. 然后,函数axis()然后绘制所需的刻度。 You can find more details here: https://www.statmethods.net/advgraphs/axes.html . 您可以在这里找到更多详细信息: https : //www.statmethods.net/advgraphs/axes.html

Meanwhile, you may want to double check the values of your ts objects: Your plot looks interesting in that the y-axis ticks were drawn at values very different from those of your dataset snapshot. 同时,您可能需要仔细检查ts对象的值:您的图看起来很有趣,因为y轴刻度线绘制的值与数据集快照的值非常不同。

By the way, Year is not a time series so you can remove that from the legend. 顺便说一句, Year不是时间序列,因此您可以将其从图例中删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM