简体   繁体   中英

Repositioning scatter plot labels in ggplot2

是否可以重新定位标签,使得在扇区(-x,y)中标签位于左侧,扇区(+ x,y)标签位于右侧?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM