那位大神帮忙看看下面的代码为什么画不出来图,哪里出问题了?十分感谢!!!
for ( count1 in 1:n){
frame()
mat <- matrix(c(1,2,3,4,5,6),nrow=3,byrow=TRUE)
layout(mat)
for(count2 in 1:6){
data %>% filter(店code==店名[(count1-1)*6+count2]) -> temp_data
temp_data$日期 <- paste(substring(temp_data$日期,1,4),"-",substring(temp_data$日期,5,6),"-",substring(temp_data$日期,7,8),sep="")
temp_data$日期 <- as.Date(temp_data$日期)
temp_data %>% arrange(日期) -> temp_data
temp_data %>% mutate(日数=row_number()) ->temp_data
qplot(日数,销售额/个数,data=temp_data,geom="line")
result <- lm(销售额/个数~日数, data=temp_data)
ggplot() +
xlab("经过日数")+
ylab("单价")+
ggtitle(paste(店名[(count1-1)*6+count2],"の单价"))+
layer(
data=temp_data,
mapping=aes(x=日数, y=销售额/个数),
geom="line",
stat="identity",
position="identity",
colour="blue",
alpha=0.5
)+
layer(
data=temp_data,
mapping=aes(x=日数, y=result$coefficients[1]+result$coefficients[2]*日数),
geom="line",
stat="identity",
position="identity",
colour="red",
alpha=0.5
)
}
file_name = paste("ID=1_","k=",count1,".pdf",sep="")
dev.copy2pdf(file=file_name)
}