2020年1月23日木曜日

The relationship between cli 1month delta and eps quarter over quater growth. Part 2



  1. separate aes(color=sign) from ggplot in order to draw integrated smooth line.
  2. use scale_color_brewer() to designate label values
  3. apply parameter needs to have dimention. don't use as.vector() beforehand.


cov <- apply.quarterly(SP5[,4],sd)["1990::2018"] /apply.quarterly(SP5[,4],mean)["1990::2018"] 
func <- function(x){if(x > mean(cov)){return("a")}else{return("b")}}
df <- data.frame(
cli=as.vector(apply.quarterly(diff(cli_xts$oecd),mean)["1990::2018"]),
eps=as.vector(diff(eps_year_xts,1)["1990::2018"]),
sign=as.vector(apply(cov,1,func)),
# sign=as.vector(year(index(diff(eps_year_xts,1)["2001::2018"]))),
cov=cov
)
p <- ggplot(df, aes(x=cli,y=eps))
p <- p + geom_point(alpha=0.95,aes(color=sign))
p <- p + geom_smooth(method = "lm")
p <- p + scale_color_brewer(palette="Set1",na.value = "grey50",name = "COV", labels = c("COV more than mean val.","COV less than mean val."))
plot(p)




0 件のコメント: