Christian Kreibich
2011-04-18 17:27:59 UTC
I am trying to produce text annotations inside a plot along lines of
various angles. The following produces a plot with a diagonal line that
has the annotation sitting correctly alongside it:
d <- data.frame(x=c(0,100), y=c(0,100))
d.anno <- data.frame(x=c(50), y=c(50))
ggplot(d, aes(x, y)) + geom_line() +
geom_text(aes(x, y*1.08), data=d.anno, label='annotation', angle=45)
ggsave('ok.png', p, width=7, height=7)
The problem here is that the correctness depends on the aspect ratio of
the plot -- if you make the plot half as tall as it is wide, for
example, then the text no longer aligns:
ggsave('rats.png', p, width=7, height=3.5)
Unfortunately in my setting I cannot manually adjust the labels to look
right. I have tried to factor the resulting aspect ratio into the angle,
but this gets messy and imprecise once you have plot grids of varying
dimensions via facets.
Is there a better way to do this?
various angles. The following produces a plot with a diagonal line that
has the annotation sitting correctly alongside it:
d <- data.frame(x=c(0,100), y=c(0,100))
d.anno <- data.frame(x=c(50), y=c(50))
ggplot(d, aes(x, y)) + geom_line() +
geom_text(aes(x, y*1.08), data=d.anno, label='annotation', angle=45)
ggsave('ok.png', p, width=7, height=7)
The problem here is that the correctness depends on the aspect ratio of
the plot -- if you make the plot half as tall as it is wide, for
example, then the text no longer aligns:
ggsave('rats.png', p, width=7, height=3.5)
Unfortunately in my setting I cannot manually adjust the labels to look
right. I have tried to factor the resulting aspect ratio into the angle,
but this gets messy and imprecise once you have plot grids of varying
dimensions via facets.
Is there a better way to do this?
--
Cheers,
Christian
Cheers,
Christian