如何在R中复制以下图表(最好使用GGplot)?
它显示了等间距收盘价仓位中正负交易量的比例。那些红色和绿色的点与解决方案的关系并不大,如果有人知道如何重现它们,那就太好了。我所做的是:
library(quantmod)
library(dplyr)
getSymbols("AAPL")
AAPL <- AAPL %>% dplyr::group_by(Gr = cut(AAPL.Close, breaks = quantile(AAPL.Close, probs = seq(0,1,0.1)), include.lowest = T)) %>% dplyr::mutate(Poz_Volume = ifelse(AAPL.Close> dplyr::lag(AAPL.Close), AAPL.Volume, 0), Neg_Volume = ifelse(AAPL.Close< dplyr::lag(AAPL.Close), Volume, 0),
Cum_Poz_Vol = c(0, cumsum(na.omit(Poz_Volume))), Cum_Neg_Vol = c(0, cumsum(na.omit(Neg_Volume))), Agg_Vol = Cum_Poz_Vol + Cum_Neg_Vol) %>%
tidyr::drop_na()
现在我被困住了,因为我不知道如何向GGplot解释如何对相应的Poz和Neg体积进行分组...在GGplot教程之后,解决方案可能类似于:
ggplot(AAPL) + geom_bar(aes(fill = ???), position = position_stack(reverse = TRUE)) +
coord_flip() + theme(legend.position = "top")
但是我不知道如何处理填充美学,如何将图叠加在价格序列上,而不是仅仅生成图形。谢谢您的帮助。