Car*_*los 3 r data-visualization ggplot2 bloomberg
我试图让一个情节看起来像 R 中的彭博终端的情节,我发现了以下 Mathematica 帖子:
https://mathematica.stackexchange.com/questions/48185/make-plot-look-like-bloomberg-terminal
我的问题是,这可以在 RI 中使用 ggplot2 完成吗?
这是第一次剪辑。它没有渐变填充,收盘价填充是一个矩形而不是指向图形的指针(我尝试annotate使用geom="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)
Run Code Online (Sandbox Code Playgroud)