数据示意
周天 0904 2011
周一 0905 5623
周二 0906 2083
周三 0907 4844
周四 0908 3655
周五 0909 4586
周六 0910 5557
周天 0911 6658
周一 0912 6490
周二 0913 5003
周三 0914 4914
周四 0915 3823
周五 0916 2632
周六 0917 1740
input the data
datafile <- "E:/Data/trade_data.txt"
dat <- read.table(file=datafile,sep="\t",stringsAsFactors=FALSE, fileEncoding = "UTF-8")
colnames(dat) <- c("week","day","sales","IDs")
dat$IDs <- as.numeric(dat$IDs)
dat$day <- as.character(dat$day)
str(dat)
weeksname <- c("周一","周二","周三","周四","周五","周六","周天")
weeksname2 <- c("月","火","水","木","金","土","日")
data_explore
summary(dat$sales)
sum(dat$sales)
mean(dat$sales)
median(dat$sales)
var(dat$sales)
mean(dat$IDs,na.rm=TRUE)
mean(dat[,3]/dat[,4],na.rm=TRUE)*30
explore_data by graph
library(ggplot2)
p2 <- ggplot(dat,aes(x=interaction(week,day),y=sales,fill=day))+geom_bar(stat="identity",position="dodge")+guides(fill=FALSE)
p2+theme(axis.text.x=element_text(angle=45,hjust=1,vjust=1))+xlab("Times")
p1 <- ggplot(dat,aes(x=week,y=sales,fill=day))+geom_bar(stat="identity",width=0.9,position="dodge")
scient <- (format(as.numeric(dat$sales),scientific=TRUE,digits=4))
p1 <- p1+geom_text(aes(label=scient),vjust = 1.5,size=4,position=position_dodge(0.9))
p1 <- p1+scale_x_discrete(limits=weeksname)+guides(fill=FALSE)
p1+ geom_text(aes(label=dat$day,y=sales-2000000),vjust = 1.5,size=3,position=position_dodge(0.9))
数值的大小以及位数
round(dat$sales,digits=-2)
signif(dat$sales,digits=3)