我试图在R中将多个图和一个表组合成一个组合图。我的情节是伟大的,直到我试图包括表以及。就在这时,我收到了这条消息:gList(...)中的错误:"gList"中只允许'grobs'。我猜它不是最好的工作,所有的图都是通过ggplots2制作的,结果是列表,表格只是一个使用可编辑函数的虚构数据框。下面是我创建表格的代码以及合并图的代码
表格代码:
table1 <- FinalPitches %>%
arrange(desc(Pitches)) %>%
kable(col.names = c("Player Name", "Pitch Type", "Pitches", "Velocity", "Horizontal Break", "Vertical Break",
"Spin Rate", "VAA", "Strike%","CSW%", "Whiff%", "Stuff+")) %>%
kable_styling()
合并代码:
# Define the first arrangeGrob
first_arrange <- arrangeGrob(
BreakChart,
LocationMap,
nrow = 1,
widths = c(0.40, 0.50) # Adjusted widths to add up to 1
)
# Define the second arrangeGrob with smaller widths
second_arrange <- arrangeGrob(
Even1,
Ahead1,
Behind1,
TwoStrikes1,
nrow = 1,
widths = c(0.15, 0.15, 0.15, 0.15) # Adjusted widths to make them smaller
)
# Define the third
third_arrange <- arrangeGrob(
table1,
nrow = 1,
widths = c(0.15) # Adjusted widths to make them smaller
)
# Combine the plots into a grid layout
combined_plot6 <- grid.arrange(
first_arrange, # First row (top)
second_arrange, # Second row (bottom)
third_arrange, # third row (bottom)
ncol = 1, # Single column layout
nrow = 3, # Dividing the grid into two rows
heights = unit(c(1, 1, 0.5), c("null", "null", "null")) # Adjusted heights for the rows
)
# Display the combined plot
print(combined_plot6)
我很抱歉没有可复制的代码,但如果任何人都可以得到它有点工作与表和情节被包括在一起,这将是了不起的,我会接受作为正确的答案。谢谢!!这是一张我想要的照片。底部的可视化是完美的,我只是不能得到表添加到图形。
1条答案
按热度按时间gab6jxml1#
这里有一个方法可以应用于您的问题:
创建于2023-06-24带有reprex v2.0.2