xts 图中的 R xlab 和 ylab
R xlab and ylab in xts plot
绘制 xts 应该很容易,但我似乎无法让 xlab 和 ylab 工作..
ylab="Price"
xlab="Date"
plot(x = basket[, 1], lty="dotted", xlab = xlab, ylab = ylab, col = "mediumblue", lwd = 2)
title("Cumulative")
这将绘制图形,但 x 轴和 y 轴上没有任何标签。
一定有一个简单的解决方案。除了那个问题之外,情节看起来应该如此。我尝试过 xts.plot、zoo.plot、xyplot,但 none 似乎可以解决问题。
数据样本
structure(c(1, 1.01463414634146, 0.926829268292683, 0.970731707317073,
0.953658536585366, 1, 0.998263888888889, 1.01159722222222, 1.05076388888889,
1.05034722222222, 1, 1.00178890876565, 0.985688729874776, 1.04293381037567,
1.04651162790698, 1, 0.976675478152698, 0.990359197636448, 1.06515316436013,
1.04571606282071), class = c("xts", "zoo"), index = structure(c(946944000,
947030400, 947116800, 947203200, 947462400), tzone = "UTC", tclass = "Date"), .Dim = 5:4, .Dimnames = list(
NULL, c("new.close", "new.close.1", "new.close.2", "new.close.3"
)))
我知道这可能不是您想要的,但它可以完成工作。另外,您可以使用 ggplot2,这比标准绘图系统更好。此外,我正在使用 ggfortify 扩展 ggplot()
处理时间序列的功能。
library(xts)
library(zoo)
library(ggfortify)
library(ggplot2)
myts = structure(
c(1, 1.01463414634146, 0.926829268292683, 0.970731707317073,
0.953658536585366, 1, 0.998263888888889, 1.01159722222222, 1.05076388888889,
1.05034722222222, 1, 1.00178890876565, 0.985688729874776, 1.04293381037567,
1.04651162790698, 1, 0.976675478152698, 0.990359197636448, 1.06515316436013,
1.04571606282071),
class = c("xts", "zoo"),
index = structure(c(946944000, 947030400,
947116800, 947203200,
947462400),
tzone = "UTC",
tclass = "Date"),
.Dim = 5:4, .Dimnames = list(NULL,
c("new.close",
"new.close.1",
"new.close.2",
"new.close.3" ) )
)
autoplot( myts[ , 1], xlab = "Date", ylab = "Price" )
由 reprex package (v0.3.0)
于 2020-05-05 创建
是plot.zoo
,不是zoo.plot
。这些都对我有用:
library(xts)
plot(as.zoo(basket[, 1]), xlab = "X", ylab = "Y")
plot.zoo(basket[, 1], xlab = "X", ylab = "Y")
library(lattice)
xyplot(basket[, 1], xlab = "X", ylab = "Y")
library(ggplot2)
autoplot(basket[, 1]) + xlab("X") + ylab("Y")
备注
basket <-
structure(c(1, 1.01463414634146, 0.926829268292683, 0.970731707317073,
0.953658536585366, 1, 0.998263888888889, 1.01159722222222, 1.05076388888889,
1.05034722222222, 1, 1.00178890876565, 0.985688729874776, 1.04293381037567,
1.04651162790698, 1, 0.976675478152698, 0.990359197636448, 1.06515316436013,
1.04571606282071), class = c("xts", "zoo"), index = structure(c(946944000,
947030400, 947116800, 947203200, 947462400), tzone = "UTC", tclass = "Date"), .Dim = 5:4, .Dimnames = list(
NULL, c("new.close", "new.close.1", "new.close.2", "new.close.3"
)))
绘制 xts 应该很容易,但我似乎无法让 xlab 和 ylab 工作..
ylab="Price"
xlab="Date"
plot(x = basket[, 1], lty="dotted", xlab = xlab, ylab = ylab, col = "mediumblue", lwd = 2)
title("Cumulative")
这将绘制图形,但 x 轴和 y 轴上没有任何标签。
一定有一个简单的解决方案。除了那个问题之外,情节看起来应该如此。我尝试过 xts.plot、zoo.plot、xyplot,但 none 似乎可以解决问题。
数据样本
structure(c(1, 1.01463414634146, 0.926829268292683, 0.970731707317073,
0.953658536585366, 1, 0.998263888888889, 1.01159722222222, 1.05076388888889,
1.05034722222222, 1, 1.00178890876565, 0.985688729874776, 1.04293381037567,
1.04651162790698, 1, 0.976675478152698, 0.990359197636448, 1.06515316436013,
1.04571606282071), class = c("xts", "zoo"), index = structure(c(946944000,
947030400, 947116800, 947203200, 947462400), tzone = "UTC", tclass = "Date"), .Dim = 5:4, .Dimnames = list(
NULL, c("new.close", "new.close.1", "new.close.2", "new.close.3"
)))
我知道这可能不是您想要的,但它可以完成工作。另外,您可以使用 ggplot2,这比标准绘图系统更好。此外,我正在使用 ggfortify 扩展 ggplot()
处理时间序列的功能。
library(xts)
library(zoo)
library(ggfortify)
library(ggplot2)
myts = structure(
c(1, 1.01463414634146, 0.926829268292683, 0.970731707317073,
0.953658536585366, 1, 0.998263888888889, 1.01159722222222, 1.05076388888889,
1.05034722222222, 1, 1.00178890876565, 0.985688729874776, 1.04293381037567,
1.04651162790698, 1, 0.976675478152698, 0.990359197636448, 1.06515316436013,
1.04571606282071),
class = c("xts", "zoo"),
index = structure(c(946944000, 947030400,
947116800, 947203200,
947462400),
tzone = "UTC",
tclass = "Date"),
.Dim = 5:4, .Dimnames = list(NULL,
c("new.close",
"new.close.1",
"new.close.2",
"new.close.3" ) )
)
autoplot( myts[ , 1], xlab = "Date", ylab = "Price" )
由 reprex package (v0.3.0)
于 2020-05-05 创建是plot.zoo
,不是zoo.plot
。这些都对我有用:
library(xts)
plot(as.zoo(basket[, 1]), xlab = "X", ylab = "Y")
plot.zoo(basket[, 1], xlab = "X", ylab = "Y")
library(lattice)
xyplot(basket[, 1], xlab = "X", ylab = "Y")
library(ggplot2)
autoplot(basket[, 1]) + xlab("X") + ylab("Y")
备注
basket <-
structure(c(1, 1.01463414634146, 0.926829268292683, 0.970731707317073,
0.953658536585366, 1, 0.998263888888889, 1.01159722222222, 1.05076388888889,
1.05034722222222, 1, 1.00178890876565, 0.985688729874776, 1.04293381037567,
1.04651162790698, 1, 0.976675478152698, 0.990359197636448, 1.06515316436013,
1.04571606282071), class = c("xts", "zoo"), index = structure(c(946944000,
947030400, 947116800, 947203200, 947462400), tzone = "UTC", tclass = "Date"), .Dim = 5:4, .Dimnames = list(
NULL, c("new.close", "new.close.1", "new.close.2", "new.close.3"
)))