当我使用 quantmod::chartSeries 绘制图表时,如何使绘图 x 标签格式与 data.frame 中的原始格式相同?感谢! 下面的代码,图表x标签不正确
test_data <- data.frame(mydate=as.Date(c('2013-1-1','2023-1-6','2023-1-20')),
open = c(1,7,8),
high=c(7,10,9),
low= c(1,3,4),
close=c(1.5,6,7.5))
quantmod::chartSeries(ts(test_data))
最佳答案
library(quantmod)
library(xts)
# Create the data.frame
test_data <- data.frame(mydate = as.Date(c('2013-1-1', '2023-1-6', '2023-1-20')),
open = c(1, 7, 8),
high = c(7, 10, 9),
low = c(1, 3, 4),
close = c(1.5, 6, 7.5))
# Convert the data.frame to an xts object
test_xts <- xts(test_data[, -1], order.by = test_data$mydate)
# Plot the chart
chartSeries(test_xts, name = "Test Chart")
关于r - ChartSeries - 如何将绘图 x 标签设置为数据框中的原始日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75887917/