绘制随机布局并填充文本
我正在尝试在 R/ 图形中绘制随机化布局。
Trt <- c(paste ("Trt#", 1:10, sep = ""))
mydes <- data.frame (block1= sample(Trt), block2 = sample(Trt), block3= sample(Trt), block4= sample( Trt), block5= sample(Trt))
plot(c(0, NCOL(mydes)), c(0, NROW(mydes)), type= "n", xlab="blocks", ylab = "range")
grid(lty = 2, col = 1)
mydes
block1 block2 block3 block4 block5
1 Trt#10 Trt#5 Trt#4 Trt#6 Trt#8
2 Trt#6 Trt#8 Trt#9 Trt#2 Trt#3
3 Trt#3 Trt#6 Trt#5 Trt#10 Trt#9
4 Trt#9 Trt#4 Trt#1 Trt#5 Trt#2
5 Trt#5 Trt#9 Trt#7 Trt#3 Trt#5
6 Trt#7 Trt#3 Trt#3 Trt#7 Trt#7
7 Trt#8 Trt#10 Trt#8 Trt#4 Trt#4
8 Trt#1 Trt#7 Trt#10 Trt#9 Trt#1
9 Trt#4 Trt#1 Trt#2 Trt#1 Trt#10
10 Trt#2 Trt#2 Trt#6 Trt#8 Trt#6
我想在每个网格矩形的中间添加文本。我知道通过一一添加文本和指定坐标会很痛苦。但我想要一个具有一些短循环的通用解决方案,它也可以应用于任何其他维度。
谢谢;
I am trying to plot randomization layout in R/ graphics.
Trt <- c(paste ("Trt#", 1:10, sep = ""))
mydes <- data.frame (block1= sample(Trt), block2 = sample(Trt), block3= sample(Trt), block4= sample( Trt), block5= sample(Trt))
plot(c(0, NCOL(mydes)), c(0, NROW(mydes)), type= "n", xlab="blocks", ylab = "range")
grid(lty = 2, col = 1)
mydes
block1 block2 block3 block4 block5
1 Trt#10 Trt#5 Trt#4 Trt#6 Trt#8
2 Trt#6 Trt#8 Trt#9 Trt#2 Trt#3
3 Trt#3 Trt#6 Trt#5 Trt#10 Trt#9
4 Trt#9 Trt#4 Trt#1 Trt#5 Trt#2
5 Trt#5 Trt#9 Trt#7 Trt#3 Trt#5
6 Trt#7 Trt#3 Trt#3 Trt#7 Trt#7
7 Trt#8 Trt#10 Trt#8 Trt#4 Trt#4
8 Trt#1 Trt#7 Trt#10 Trt#9 Trt#1
9 Trt#4 Trt#1 Trt#2 Trt#1 Trt#10
10 Trt#2 Trt#2 Trt#6 Trt#8 Trt#6
I want to add the text in middle of each grid rectangle. I know I can do it painfully by adding text and specifying coordinates one by one. But I want a generalized solution with some short of loop, that can be applied to any other dimensions as well.
Thanks;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是在 ggplot 中执行此操作的一种方法:
因为您想要绘制这样,您不仅可以打印表格,还可以使用色标来映射具有相同值的处理:
Here is a way of doing it in
ggplot
:Since you want to plot this, rather than just printing a table, you may as well use a colour scale to map treatments with the same value:
您可以尝试以下操作:
问题是您的网格在 y 方向包含 2 个单元格...
You can try this:
Problem is that your grid contains 2 cells in the y-direction...