绘制R

时间:2018-02-27 03:08:18

标签: r plot data-analysis

这是在R ver3.4.2编程中。我即将绘制数据帧的某个变量,比如Y,与日期的工作日。我已经通过了一些参考文献,但到目前为止还没有。我尝试了以下内容:(数据框有日期,时间和Y)

library(dplyr)
library(lubridate)
library(datasets)
df$Date<- as.Date(df$Date, "%d/%m/%Y")
df$Time<- strptime(df$Time, "%H:%M:%S")
df$Time<- as.POSIXct(df$Time)
#select data for certain dates
selected_data<-with(df, df[(Date >= "2017-01-12" & Date <= "2017-01-13"),])
Y<- as.numeric(as.character(selected_data$Y))
#these are my trials in trying to plot the weekdays
#trial 1
wkdays <- weekdays(selected_data$Date)
#trial 2
dat <- format(selected_data$Date,"%Y-%m-%d")

pl<-plot(dat,Y, type="l" , ylab = "Y", xlab=" ")
#pl<-plot(wkdays, Y, type="l" ,xaxt="n", ylab = "Y", xlab=" ")
#pl<- plot(Y, type="l", ylab = "Y", xlab=" ")
axis(1,at=as.Date.numeric(selected_data$Date), labels=format(weekday))
#axis.Date(1, at=seq(weekday), "days",labels = TRUE)
#axis.Date(1, at=seq(min(wkdays),max(wkdays), by = "%d"), "days",labels = TRUE,tcl = -0.2)
axis(2, at= seq(0, max(Y), by = 2))

输出应该是Y数据与指数的线图,其中刻度标记为日期(周一,周二等)的工作日,并且具有一定的刻度间隔。

如果有人有答案的链接(也许我有diff关键字),请帮助并在下面分享。谢谢!

以下是一个示例数据集:

Date;Time;Y;
2017-01-12;2018-02-27 00:00:00;"0.715";
2017-01-12;2018-02-27 00:01:00;"0.438";
2017-01-12;2018-02-27 00:02:00;"0.734";
2017-01-12;2018-02-27 00:03:00;"0.646";
2017-01-12;2018-02-27 13:19:00;"1.268";
2017-01-13;2018-02-27 13:20:00;"0.108";
2017-01-13;2018-02-27 13:21:00;"0.961";
2017-01-13;2018-02-27 13:22:00;"0.570";
2017-01-13;2018-02-27 13:23:00;"0.192";
2017-01-13;2018-02-27 13:24:00;"1.280";

1 个答案:

答案 0 :(得分:0)

以下是使用<li v-for="(catalog, index) in catalogs">this index : {{index + 1}}</li> 包中的array.length的解决方案。查看更多herehere

由于您没有提供数据,因此我生成了一个随机数据。

<p>Total Count: {{ catalogs.length }}</p>

包括日期和时间月:

scale_x_date(date_breaks = "day", date_labels = "%a")

reprex package(v0.2.0)创建于2018-02-26。