【发布时间】:2020-06-17 05:27:17
【问题描述】:
我想将 3 个地块无缝地合并在一起。我的问题是情节略有偏移,即使我没有边界地绘制它们,它们也不会在情节 1 和 2/情节 2 和 3 之间无缝合并。
library(tidyverse)
library(gridExtra)
plot1 <- ggplot(df) +
theme_dark() +
geom_line(aes(y = Price, x = time, color = "#00FFFF"), size = 0.7) +
geom_area(aes(y = Price, x = time), fill = "#00FFFF", alpha = .1) +
theme(axis.title.x=element_blank(),
axis.text.x=element_blank(),
axis.ticks.x=element_blank(),
legend.position = c(.1, .95),
legend.justification = c("right", "top"),
legend.box.just = "right",
legend.margin = margin(3, 3, 3, 3),
plot.margin = margin(0,-0.5,-0.5,-0.5),
plot.background = element_rect(fill = "#808080")) +
scale_colour_manual(name = "Price",
values = c("#00FFFF" = "#00FFFF"), labels = c("Stock")) +
labs(y = "")
#
plot1
#
plot2 <- ggplot(df) +
theme_dark() +
geom_bar(aes(x = time, y = B, fill = "green"), stat = "identity") +
geom_bar(aes(x = time, y = S, fill = "red"), stat = "identity") +
theme(axis.title.x=element_blank(),
axis.text.x=element_blank(),
axis.ticks.x=element_blank(),
panel.border = element_blank(),
legend.position = c(.1, .95),
legend.justification = c("right", "top"),
legend.box.just = "right",
legend.margin = margin(3, 3, 3, 3),
plot.margin = margin(-0.75,-0.5,0,-0.5),
plot.background = element_rect(fill = "#808080")) +
scale_fill_identity(name = "Volume",
guide = "legend", labels = c("B", "S")) +
labs(y = "")
#
plot2
#
plot3 <- ggplot(df) +
theme_dark() +
geom_line(aes(y = EMA_short, x = time, color = "blue"), size = 0.7) +
geom_area(aes(y = EMA_short, x = time), fill = "blue", alpha = .1) +
geom_line(aes(y = EMA_long, x = time, color = "yellow"), size = 0.7) +
geom_area(aes(y = EMA_long, x = time), fill = "yellow", alpha = .1) +
theme(axis.title.x=element_blank(),
axis.ticks.x=element_blank(),
panel.border = element_blank(),
legend.position = c(.1, .95),
legend.justification = c("right", "top"),
legend.box.just = "right",
legend.margin = margin(3, 3, 3, 3),
plot.margin = margin(-0.75,-0.5,2,-0.5),
plot.background = element_rect(fill = "#808080")) +
scale_colour_manual(name = "EMA",
values = c("blue" = "blue", "yellow" = "yellow"), labels = c("EMA50", "EMA200")) +
labs(y = "")
#
plot3
#
gA <- ggplotGrob(plot1)
gB <- ggplotGrob(plot2)
gC <- ggplotGrob(plot3)
grid::grid.newpage()
grid::grid.draw(rbind(gA, gB, gC))
感谢您的任何建议。
编辑
感谢您提供非常有帮助的答案。我现在只有两个小的光学问题。尽管我将所有图例定位相同,但它们位于其他位置。我应该将它们全部格式化成相同的大小吗?可惜左边有两个小白点,如图。我已经尝试让边缘越来越小,但那里的斑点总是保持白色。我在上面更新了我的新代码。谢谢!
【问题讨论】:
-
这个SO answer 可能会有所帮助。
-
我建议考虑
patchwork包:patchwork.data-imaginist.com/articles/guides/multipage.html -
谢谢。换档问题解决了。