chartSeries -如何在dataframe中将plot x标签作为原始日期

jgwigjjp  于 2023-04-03  发布在  其他
关注(0)|答案(1)|浏览(64)

在使用quantmod::chartSeries绘制图表时,如何使data.frame中的plot x标签格式保持原样?谢谢!下面的代码,图表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))
o2rvlv0m

o2rvlv0m1#

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")

相关问题