Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Repositioning scatter plot labels in ggplot2

Tags:

r

ggplot2

Is it possible to reposition the labels such that in sector (-x,y) the label is on the left and sector (+x,y) the label is on the right?

like image 439
Brandon Bertelsen Avatar asked Feb 28 '23 21:02

Brandon Bertelsen


1 Answers

I'm not definitely sure if this is what you were looking for:

library("ggplot2")
tmp <- data.frame(x=-5:5, y=rnorm(11), lab=LETTERS[1:11])
p <- ggplot(aes(x=x, y=y, label=lab), data=tmp) +
     geom_point() +
     geom_text(data=subset(tmp, x > 0), hjust=-0.5) +
     geom_text(data=subset(tmp, x <= 0), hjust=1.5)
print(p)

geom_text labeling http://img8.imageshack.us/img8/1056/geomtext.png

like image 116
rcs Avatar answered Mar 08 '23 17:03

rcs