在當前情節中,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' )
uj5u.com熱心網友回復:
問題是光柵物件被放置在你的情節中間。檢查ggplot() annotation_custom(rasterGrob(ft_raster))沒有theme_void。您可以使用柵格的坐標(順便說一下,Infs 是默認值...
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()
# play around with this !
annotation_custom(rasterGrob(ft_raster), xmax = 0.2)
cowplot::plot_grid(p1, p2, nrow = 2, ncol = 1, rel_heights = c(1, 1) )

由reprex 包(v2.0.1)于 2022-06-08 創建
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/488001.html
