2015-09-09 52 views
2

我试图做图看起来像R A彭博终端的那些彭博情节,我发现数学以下职位:制作情节看起来像R中

https://mathematica.stackexchange.com/questions/48185/make-plot-look-like-bloomberg-terminal

我的问题是,这可以在RI与ggplot2思考吗?

+4

那你试试这么远吗? –

+0

'quantmod'包中的'chartSeries(...)'旨在完成此操作。它非常接近。如果你在价格时间系列下面寻找渐变填充,那么我不这么认为。 – jlhoward

+0

是的。可以办到。 R主机中的'?theme'。考虑加入你对'ggthemes'的做法! – hrbrmstr

回答

4

这是第一次切割。它没有渐变填充,收盘价格填充是一个矩形,而不是指向图形的指针(我试过annotategeom="segment"以获得箭头背景,但它看起来像这不适合日期)。对于一般用途,它还需要一些逻辑,而不是硬编码,以决定为右边的收盘价格文本分配多少区域。我还没有包含高,低,平均值等的面板,可以使用annotate加上面板。

library(ggplot2) 

set.seed(199) 
dat = data.frame(date = seq(as.Date("2013/10/01"), as.Date("2013/12/31"), by="1 day"), 
       price = cumsum(rnorm(92, 0, 1)) + 100) 

ggplot(dat, aes(date, y=price)) + 
    geom_area(fill="navyblue", colour="white", alpha=0.5) + 
    theme(plot.background=element_rect(fill="black"), 
     panel.background=element_rect(fill="#101040"), 
     panel.grid.minor=element_blank(), 
     panel.grid.major=element_line(linetype=2), 
     axis.text=element_text(size=15, colour="white")) + 
    coord_cartesian(ylim=c(min(dat$price) - 1, max(dat$price) + 1), 
        xlim=c(min(dat$date)-2, max(dat$date)+10)) + 
    annotate("rect", xmin=max(dat$date) + 0.75, xmax=max(dat$date) + 7.25, 
      ymin=dat$price[dat$date==max(dat$date)] - 0.25, 
      ymax=dat$price[dat$date==max(dat$date)] + 0.25, fill="white", colour="black") + 
    annotate("text", max(dat$date) + 1, dat$price[dat$date==max(dat$date)], 
      label=paste0("$", round(dat$price[dat$date==max(dat$date)],2)), 
      colour="black", hjust=0) 

enter image description here