添加表格(对齐的文本块)以在R中绘图 [英] Add table (aligned text blocks) to plot in R
本文介绍了添加表格(对齐的文本块)以在R中绘图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在 R 中的图中添加一张小表(例如,作为图例).我想到的是这样的东西:
I'd like to add a small table (for example as a legend) to a plot in R. I think of something like:
t <- wantedTableMethod(
row("param1", "param2", "param3", "param4")
, row(value11, value12, value13, cell(value14, adj=0))
, row(value21, value22, value23, value24)
, row(value31, value32, value33, cell(value34, adj=1))
border = F
)
plot(1,1)
legend("topleft", t)
列的所有值应具有相同的偏移量.在 R 中是否可能发生这种情况,还是我需要手动对齐每个值?
All values of a column should have the same offset. Is something like this possible in R, or do I need to align each value manually?
推荐答案
plotrix
软件包具有addtable2plot
函数,您可以将data.frame
或matrix
传递给
The plotrix
package has a addtable2plot
function you can pass a data.frame
or matrix
to
使用帮助页面中的示例
library(plotrix)
testdf<-data.frame(Before=c(10,7,5,9),During=c(8,6,2,5),After=c(5,3,4,3))
rownames(testdf)<-c("Red","Green","Blue","Lightblue")
barp(testdf,main="Test addtable2plot",ylab="Value",
names.arg=colnames(testdf),col=2:5)
# show most of the options
addtable2plot(0.7 ,8,testdf,bty="o",display.rownames=TRUE,hlines=TRUE,
vlines=TRUE,title="The table")
它旨在与legend
尽可能相似地工作.
It is designed to work as similarly to legend
as possible.
这篇关于添加表格(对齐的文本块)以在R中绘图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文