-3
我的數據是這樣的:如何更改ggplot2中Y軸的標題?
test_data <- data.frame(
var0 = 100 + c(0, cumsum(runif(49, -20, 20))),
var1 = 150 + c(0, cumsum(runif(49, -10, 10))),
date = seq.Date(as.Date("2002-01-01"), by="1 month", length.out=100))
要繪製兩個時間序列var0和VAR1在同一張圖,與日期在x軸,使用GGPLOT2
ggplot(test_data, aes(date)) +
geom_line(aes(y = var0, colour = "var0")) +
geom_line(aes(y = var1, colour = "var1"))
這將做工精細繪製不同顏色的兩個時間序列,但Y軸的標題和圖例將爲「var0」。
- 如何改變Y軸的標題和圖例,例如,變量值
- 如何改變都var0和VAR1線條的顏色
由於
所有的問題已經在stackoverflow上得到了解答,例如[here](http:// stacko verflow.com/questions/10438752/adding-x-and-y-axis-labels-in-ggplot2)和[這裏](http://stackoverflow.com/questions/5171263/r-changing-line-colors-with -ggplot)和[here](http://stackoverflow.com/questions/5911567/how-can-i-change-the-title-of-a-ggplot2-legend) –