不能与牛仔套件保持一致
在当前图中,p2
现在以中心为中心。我希望p2
与左侧的p1
对齐。我尝试了plot_grid中的一些参数,但是图像根本没有更改。
library(ggplot2)
library(flextable)
library(grid)
library(cowplot)
library(tidyverse)
mydf <- tibble(a = c(1,2,3,4,5,4),
b = c(4,4,4,3,3,3))
p1 <- mydf %>% ggplot(aes(x = a, y = b, color = as.factor(b))) + geom_point()
ft_raster <- mydf %>% flextable::flextable() %>%
as_raster()
p2 <- ggplot() +
theme_void() +
annotation_custom(rasterGrob(ft_raster), xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf)
# orginal plot
cowplot::plot_grid(p1, p2, nrow = 2, ncol = 1, rel_heights = c(1, 1) )
# left align plot (Nothing changed with orginal plot)
cowplot::plot_grid(p1, p2, nrow = 2, ncol = 1, rel_heights = c(1, 1), align = 'v' )
cowplot::plot_grid(p1, p2, nrow = 2, ncol = 1, rel_heights = c(1, 1), axis = 'l' )
cowplot::plot_grid(p1, p2, nrow = 2, ncol = 1, rel_heights = c(1, 1), axis = 'tblr' )
In the current plot, p2
is now centered. I want p2
to be aligned with p1
on the left. I tried some of the parameters in plot_grid, but the image didn't change at all.
library(ggplot2)
library(flextable)
library(grid)
library(cowplot)
library(tidyverse)
mydf <- tibble(a = c(1,2,3,4,5,4),
b = c(4,4,4,3,3,3))
p1 <- mydf %>% ggplot(aes(x = a, y = b, color = as.factor(b))) + geom_point()
ft_raster <- mydf %>% flextable::flextable() %>%
as_raster()
p2 <- ggplot() +
theme_void() +
annotation_custom(rasterGrob(ft_raster), xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf)
# orginal plot
cowplot::plot_grid(p1, p2, nrow = 2, ncol = 1, rel_heights = c(1, 1) )
# left align plot (Nothing changed with orginal plot)
cowplot::plot_grid(p1, p2, nrow = 2, ncol = 1, rel_heights = c(1, 1), align = 'v' )
cowplot::plot_grid(p1, p2, nrow = 2, ncol = 1, rel_heights = c(1, 1), axis = 'l' )
cowplot::plot_grid(p1, p2, nrow = 2, ncol = 1, rel_heights = c(1, 1), axis = 'tblr' )
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题在于,将栅格对象放在剧情中间。检查
ggplot() + Annotation_custom(rasterGrob(ft_raster))
没有them them_void
。您可以与栅格的坐标一起玩(顺便说一句,inf
s是默认值...在2022-06-08创建的 reprex package (v2.0.1)< /sup>
The problem is that the raster object is placed bang in the middle of your plot. Check
ggplot() + annotation_custom(rasterGrob(ft_raster))
withouttheme_void
. You can play around with the coordinates for your raster (by the way, theInf
s are defaults...Created on 2022-06-08 by the reprex package (v2.0.1)