定位图和表 [英] positioning plots and table

查看:59
本文介绍了定位图和表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想绘制两个直方图并将表格添加到 pdf 文件中.使用布局函数,我设法绘制了直方图(使用 hist 函数绘制了它们),但是当我使用 gridExtra 包中的 grid.table 函数添加表格时,表格被布置在直方图上,我是无法正确定位它们.我尝试过 addtable2plot 函数,但我觉得它在视觉上并不吸引人.

I would like to plot two histograms and add a table to a pdf file. With the layout function I managed to plot the histograms (plotted them using hist function) where I want them to be but when I used grid.table function from the gridExtra package to add the table the table is laid out on the histograms and I am not able to position them properly. I have tried addtable2plot function but I dont find it visually appealing.

对如何解决这个问题有任何想法吗?

Any thoughts on How do I get around this?

我希望我的 pdf 看起来像这样

I want my pdf to look like this

histogram1 histogram2
t    a    b   l     e 

基本上,一行有两列,另一行只有一列.这就是我所做的.

Essentially, one row with two columns and another row with just one column. This is what I did.

require(gridExtra)
layout(matrix(c(1,2,3,3),2,2,byrow=T),heights=c(1,1))
count_table=table(cut(tab$Longest_OHR,breaks=c(0,0.05,0.10,0.15,0.20,0.25,0.30,0.35,0.40,0.45,0.50,0.55,0.60,0.65,0.70,0.75,0.80,0.85,0.90,0.95,1.00)))
ysize=max(count_table)+1000
hist(tab$Longest_OHR,xlab="OHR longest",ylim=c(0,ysize))

count_table=table(cut(tab$Sum_of_OHR.s,breaks=c(0,0.05,0.10,0.15,0.20,0.25,0.30,0.35,0.40,0.45,0.50,0.55,0.60,0.65,0.70,0.75,0.80,0.85,0.90,0.95,1.00)))
ysize=max(count_table)+1000
hist(tab$Sum_of_OHR.s,xlab="OHR Sum",ylim=c(0,ysize))

tmp <- table(cut(tab$Length_of_Gene.Protein, breaks = c(0,100,200,500,1000,2000,5000,10000,1000000000)), cut(tab$Sum_of_OHR.s, breaks = (0:10)/10))
grid.table(tmp)
dev.off()

任何帮助将不胜感激.

公羊

推荐答案

以下是如何将两个 base 图和一个 grid.table 合并到同一个图形中的示例.

Here's an example of how to combine two base plots and a grid.table in the same figure.

library(gridExtra)

layout(matrix(c(1,0,2,0), 2))
hist(iris$Sepal.Length, col="lightblue")
hist(iris$Sepal.Width, col="lightblue")

pushViewport(viewport(y=.25,height=.5))
grid.table(head(iris), h.even.alpha=1, h.odd.alpha=1,
           v.even.alpha=0.5, v.odd.alpha=1)

发送到 viewport 的坐标是面板的中心.太清楚它的边界在哪里你可以调用 grid.rect().

The coordinates sent to viewport are the center of the panel. Too see exactly where its boundaries are you can call grid.rect().

这篇关于定位图和表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆