此代码已成功收集并绑定了多个文件中的数据。通过使用ggplot2,我得到了整洁的x轴标签,因为x标签是按间隔打印的。但是,ggplot将所有缺少的日期放在一起,使其并排有尖刺的图案和非常直线/间隙看起来并不好,所以我切换到plotly。但是,我无法在绘图中绘制平均值线,并且x轴标签打印得非常紧密。如何在图中包括均线并在x轴标签中应用间隔?
filenames <- list.files(path = "c:/Users/HP/Documents/",
full.names = T)
library(plyr)
import_lists <- llply(filenames, read.csv)
data <- ldply(import_lists)
data <- as.data.frame(data)
data$Date <- as.Date(data$Date, format = "%Y-%m-%d")
dts <- as.Date(as.list.data.frame(data$Date))
library(plotly)
library(zoo)
plot_ly(data, x = dts, y = data$CAPE.using.virtual.temperature,
type = "scatter", mode = "lines") %>%
layout(xaxis = list (type = "category"),
yaxis = list(title = "CINE Index"),
title = "1979-2014 (NDJ)")
#find the mean value
# m <- mean(data$CAPE.using.virtual.temperature)` not working