在绘图的空白区域中打印data.frame

Nat*_*nos 2 plot r

我希望将输出print(df.to.print)打印在绘图上.如果我可以在"传奇"(...)的调用中放置toplefttopright喜欢这个位置会很棒,但这只是一个奖励.

一些代码:

# A data.frame to play with
df.to.print <- structure(list(p.val = c(0.05, 0.1), self = c(0.0498, 0.0997), 
    H2007.REML = c(0, 0.01), H2007.ref = c(0, 0)), .Names = c("p.val", 
"self", "H2007.REML", "H2007.ref"), row.names = c(NA, -2L), class = "data.frame")

# A simple plot
plot(1)
text(1,1, df.to.print )
# All of the entries are overlapping

# I can insert newlines easily enough
plot(1)
text(1,1, paste(as.character(df.to.print), collapse='\n'))

# But that looses all of the nice formatting in the data.frame.
# Which is easy enough to get on the console with: 
print(df.to.print)

# Bonus points for 'topleft', 'topright', etc. like in legend().
Run Code Online (Sandbox Code Playgroud)

任何帮助,将不胜感激.

The*_*ras 9

试试这个:

plot(1)
text(0.6,1, paste(capture.output(df.to.print), collapse='\n'), pos=4, family="monospace")
Run Code Online (Sandbox Code Playgroud)

pos=4将文本放在指定坐标的右侧,并保留左对齐.尝试使用固定空间字体.