Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R cowplot\u网格函数将表格绘制为图像和树状图_R_Cowplot - Fatal编程技术网

R cowplot\u网格函数将表格绘制为图像和树状图

R cowplot\u网格函数将表格绘制为图像和树状图,r,cowplot,R,Cowplot,我试图使用cowplot中的plot_grid函数来制作一个定制的绘图,顶行有一个树状图,第二行有两个表(彼此相邻)。现在,我的树状图和表格被绘制出来,但是在两个单独的PDF上。有没有办法让它们都在同一页上绘图?下面是我的代码片段: pdf("test.pdf", width = 12, height = 10) x <-tableGrob(frames[[1]]) y <-tableGrob(frames[[2]]) plot.clus <-plot(test1,la

我试图使用cowplot中的plot_grid函数来制作一个定制的绘图,顶行有一个树状图,第二行有两个表(彼此相邻)。现在,我的树状图和表格被绘制出来,但是在两个单独的PDF上。有没有办法让它们都在同一页上绘图?下面是我的代码片段:

 pdf("test.pdf", width = 12, height = 10)
 x <-tableGrob(frames[[1]])
 y <-tableGrob(frames[[2]])
 plot.clus <-plot(test1,label=diseaseDuration,main=label)
 tables<-grid.arrange(x,y,nrow=1)
 plot_grid(bottom_row,tables)

使用
plot.clus
代替
z
plot

library( 'ggplot2' )
library( 'cowplot' )
library( 'gridExtra' )

x <- tableGrob( d = data.frame( x = 1:5, y = 1:5 ) )
y <- tableGrob( d = data.frame( x = 1:5, y = 1:5 ) )
z <- ggplot( data = data.frame( x = 1:5, y = 1:5 ), 
             mapping = aes( x = x, y = y ) ) + 
  geom_line( color = 'red' )

p <- ggdraw() +
  draw_plot( plot = z, x = 0, y = .5, width = 1, height = .5 ) +  # z
  draw_plot( plot = x, x = 0, y = 0, width = .5, height = .5 ) +  # x
  draw_plot( plot = y, x = .5, y = 0, width = .5, height = .5 ) + # y 
  draw_plot_label( label = c( "A", "B", "C" ),                    # labels
                   x = c( 0, 0, 0.5 ),
                   y = c( 1, 0.5, 0.5 ), 
                   size = 16 )
# save plot as pdf
save_plot( filename = "test.pdf", plot = p, base_height = 4, base_width = 4 )
库('ggplot2')
库('cowplot')
库('gridExtra')

x Sathish,谢谢你的回复。由于my plot.clus不是ggplot或GTTable类对象,因此上述内容实际上不起作用。我得到以下错误:ggplot_到gtutable(plot)中的错误:参数必须是“ggplot”或“gtable”类,通过执行
dput(data)
发布用于集群图的数据。您是否使用了分层聚类算法?请在您的问题中添加
dput
命令的输出,而不是在注释部分Sathish:是的,我使用了分层聚类。我已经添加了dput输出的示例。您在那里提供的数据没有帮助。您最好尝试
ggdendro
自行打包以创建与ggplot兼容的树状图。
library( 'ggplot2' )
library( 'cowplot' )
library( 'gridExtra' )

x <- tableGrob( d = data.frame( x = 1:5, y = 1:5 ) )
y <- tableGrob( d = data.frame( x = 1:5, y = 1:5 ) )
z <- ggplot( data = data.frame( x = 1:5, y = 1:5 ), 
             mapping = aes( x = x, y = y ) ) + 
  geom_line( color = 'red' )

p <- ggdraw() +
  draw_plot( plot = z, x = 0, y = .5, width = 1, height = .5 ) +  # z
  draw_plot( plot = x, x = 0, y = 0, width = .5, height = .5 ) +  # x
  draw_plot( plot = y, x = .5, y = 0, width = .5, height = .5 ) + # y 
  draw_plot_label( label = c( "A", "B", "C" ),                    # labels
                   x = c( 0, 0, 0.5 ),
                   y = c( 1, 0.5, 0.5 ), 
                   size = 16 )
# save plot as pdf
save_plot( filename = "test.pdf", plot = p, base_height = 4, base_width = 4 )