如何将文本标签放置在独立于数据的图上? [英] How to put a text label on a plot located independently from the data?
问题描述
我试图在ggplot上放置一个文本标签,但我不想在数据坐标中给出标签的坐标,而是使用某种与数据无关的坐标。
我知道转换技巧:
xrng< - 范围(x)
yrng< - 范围(y)
绘图< - 绘图+注释(text,x = xrng [2],y = yrng [2],label =bla)#右上角的绘图标签
但是,对于具有对数刻度的绘图,这并不适用(并且您必须执行转换,可能并不总是像在这个例子中一样简单)。
任何想法?
ggplot2
grid
图形,因此您可以使用 grid
命令来标注图。
'pre>
library('ggplot2')
library('grid')
qplot(rnorm(10))
grid.text('my标签')
?grid.text
给出指定坐标的几种方法。也许其中一个会对你的情况有意义。
I am trying to put a text label on a ggplot, but I do not want to give the coordinates of the label in the data coordinates, but use some kind of coordinates that are not related to the data. I know the transformation trick:
xrng <- range(x)
yrng <- range(y)
plot <- plot + annotate("text",x = xrng[2], y = yrng[2], label="bla") # plot label on top right
But this does not work well for plots with a logarithmic scale (and you have to do the transformation, which may not always be as easy as in the example). Any ideas?
ggplot2
plots are made with grid
graphics so you can use grid
commands to annotate the plot.
library('ggplot2')
library('grid')
qplot(rnorm(10))
grid.text('my label')
?grid.text
gives several ways of specifying the coordinates. Maybe one of them will make sense in your case.
这篇关于如何将文本标签放置在独立于数据的图上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!