将纯文本面板添加到基本图形布局 [英] Adding a text only panel to base graphics layout

查看:89
本文介绍了将纯文本面板添加到基本图形布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

3个地块分为2行2列

3 plots arranged in 2 rows and 2 columns

 attach(mtcars)
 par(mfrow=c(2,2))
 plot(wt,mpg, main="Scatterplot of wt vs. mpg")
 plot(wt,disp, main="Scatterplot of wt vs disp")
 boxplot(wt, main="Boxplot of wt")

但是如何创建仅包含文本的面板,然后将其添加到网格中的第四个位置.道歉.我现在看到,就像许多查询者一样,我要求您从我的代码中读懂我的想法或直觉,我希望文本在空白区域的位置网格中以左对齐的形式排列.

But how do I create a panel with just text and then add it to the fourth position in the grid. Apologies. I see now that like many quesioners I was asking you to read my mind or intuit from my code that I expected the text to be arranged left-justified in a grid of locations in the blank space.

(出于某种原因,这似乎是完全合理的问题,但是尽管没有获得密切的投票或提名提供重复副本,它还是被删除了.我将我凑齐的内容作为答案,但是可能会有更优雅的解决方案.我确实查看过类似问题提名的标题,但没有找到与该问题匹配的内容.)

(For some reason this seemed perfectly reasonable to ask but it was deleted, despite no close votes or nomination for duplicates offered. I'll put in what I had cobbled together, as an answer but there might be more elegant solutions. I did look at the titles for nominations of similar questions, but didn't find any that matched this problem.)

plot(1:100, 1:100, axes=FALSE, ylab="", xlab="", type="n")
text( rep(c(1,50), each=10), rep( seq(1, 100, by=10),2), labels=letters[1:20])

我想知道一个事实,那就是细粒度的网格是否是正确的方法.也许只有正确的行数和列数并且使用左对齐的文本的粗网格将更像表格.带有洗礼的tableGrob的gridExtra软件包也可能是一个富有成效的方向.

I've wondered after the fact whether a fine grained grid was the right way to do it. Perhaps a coarser grid with just the right number of rows and columns and using left justified text would be more table-like. The gridExtra package with baptiste's tableGrob might also be a productive direction.

情节"的替代文本参数可能是:

An alternate text argument to "plot" might be:

txt <- structure(c("am", "carb", "cyl", "disp", "drat", "gear", "hp", 
                   "mpg", "qsec", "vs", "wt", "this"), .Dim = 3:4)


> txt
     [,1]   [,2]   [,3]   [,4]  
[1,] "am"   "disp" "hp"   "vs"  
[2,] "carb" "drat" "mpg"  "wt"  
[3,] "cyl"  "gear" "qsec" "this"

推荐答案

这里是一个示例,

library(gplots)
textplot(txt)

plotrix中也有addtable2plot,另一种解决方案是将基本图形和网格图形与gridBase程序包混合,然后从gridExtra程序包中放置一个tableGrob.

There's also addtable2plot in plotrix, and an alternative solution would be to mix base and grid graphics with the gridBase package, and place a tableGrob from the gridExtra package.

这篇关于将纯文本面板添加到基本图形布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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