cowplot plot_grid 函数将 table 绘制为图像和树状图
cowplot plot_grid function to plot table as image and dendrogram
我正在尝试使用 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)
用于聚类的 dput 输出片段 (hclust):
structure(list(merge = structure(c(-61L, -41L, -49L, 1L, -16L...),
height = c(4.23833720098634e-13, 6.36507320251999e-13.......),
order = c(5L, 57L, 12L, 7L, 66L, 31L, 55L, 6L, 10L, 37L,..),
labels = c("ABC00001", "ABC00002", "ABC00003",......),
method = "ward.D",
call = hclust(d = data, method = "ward.D"), dist.method =
"euclidean"), .Names = c("merge", "height", "order", "labels", "method", "call", "dist.method"), class = "hclust")
使用 plot.clus
代替 z
图
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 )
我正在尝试使用 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)
用于聚类的 dput 输出片段 (hclust):
structure(list(merge = structure(c(-61L, -41L, -49L, 1L, -16L...),
height = c(4.23833720098634e-13, 6.36507320251999e-13.......),
order = c(5L, 57L, 12L, 7L, 66L, 31L, 55L, 6L, 10L, 37L,..),
labels = c("ABC00001", "ABC00002", "ABC00003",......),
method = "ward.D",
call = hclust(d = data, method = "ward.D"), dist.method =
"euclidean"), .Names = c("merge", "height", "order", "labels", "method", "call", "dist.method"), class = "hclust")
使用 plot.clus
代替 z
图
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 )