adjusting the location of the geom_text labels

3,434 views
Skip to first unread message

Shai

unread,
Oct 17, 2010, 1:12:00 AM10/17/10
to ggplot2
Hi!!

I have a problem setting the position of the geom_text. I would like
to plt the sample size of every sample I have inside the bar, in the
same vertical position (lets say in the bottom of each bar). But I can
only get them right above the bars, in different adjustments... Here
is an example code.

#Example data frame taken from igreg in an earlie post here:
#http://groups.google.com/group/ggplot2/browse_thread/thread/
72e2e46c42cde2a7/b95dc1796104df65?# lnk=gst&q=read
+books#b95dc1796104df65

d.frame <- matrix (c(rep("read.books",3),rep("watch.tv", 3),
"often","sometimes","never","often","sometimes","never",
150,200,50,50,100,250),
nrow=6,ncol=3,byrow=F)
d.frame <- as.data.frame(d.frame)
names(d.frame) <-c("variable","value","frequ")
d.frame
dodge <- position_dodge(width=0.9)
pl <- ggplot(d.frame, aes(x=variable, y=as.numeric(frequ),fill
=value))
pl <- pl + geom_bar(stat="identity",position="dodge")
pl <- pl+geom_text(aes(label=frequ),position=position_dodge(width=1),
size=8)
pl

Thanks!
shai

Ista Zahn

unread,
Oct 17, 2010, 10:24:20 AM10/17/10
to Shai, ggplot2
Sure, just set the y position:

pl+geom_text(aes(y=.5, label=frequ),position=position_dodge(width=1), size=8)

-Ista

> --
> You received this message because you are subscribed to the ggplot2 mailing list.
> Please provide a reproducible example: http://gist.github.com/270442
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
>

--
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org

Reply all
Reply to author
Forward
0 new messages