如何在 R 中向晶格线框添加文本
大家好,
我想在线框图中添加浮动文本,但我很困惑。我当然可以将文本添加为标题(例如 main="Hello World"),但我不想在标题中包含我的特定文本
这是一个示例线框:
library(lattice)
#set up some simplified data
x <- seq(-.8, .8, .1)
y <- seq(-.8, .8, .1)
myGrid <- data.frame(expand.grid(x,y))
colnames(myGrid) <- c("x","y")
myGrid$z <- myGrid$x + myGrid$y
wireframe(
myGrid$z ~ myGrid$x * myGrid$y,
xlab="X", ylab="Y", zlab="Z",
scales = list(z.ticks=5, arrows=FALSE, col="black", font=3, tck=1)
)
如果我想在该图中浮动某处添加“Hello World”我该怎么做?
Good Day All,
I want to add text floating in my wireframe plot and I am rather confused. I can certainly add the text as a title (e.g. main="Hello World") but I would rather not have my particular text in the title
Here is a sample wireframe:
library(lattice)
#set up some simplified data
x <- seq(-.8, .8, .1)
y <- seq(-.8, .8, .1)
myGrid <- data.frame(expand.grid(x,y))
colnames(myGrid) <- c("x","y")
myGrid$z <- myGrid$x + myGrid$y
wireframe(
myGrid$z ~ myGrid$x * myGrid$y,
xlab="X", ylab="Y", zlab="Z",
scales = list(z.ticks=5, arrows=FALSE, col="black", font=3, tck=1)
)
If I wanted to add "Hello World" in this plot floating somewhere how would I do that ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
重写面板函数并使用
grid.text
添加文本。Override the panel function and add text with
grid.text
.或者,您可以在使用
unit
函数绘制线框后添加文本,该函数允许您指定文本的位置。如果您使用
"npc"
作为单位,则图形的总宽度和高度为 1。因此上面的示例将在右上角显示您的文本,而x=y=unit (0.5, "npc")
会将其绘制在中心。Alternatively you could add the text after you plotted your wireframe with
The
unit
function allows you to specify the location of the text. If you use"npc"
as your unit, the total width and height of your graph is 1. So the example above would display your text in the top right corner whilex=y=unit(0.5, "npc")
would plot it in the center.