Dimitri Liakhovitski
2013-Nov-01 15:19 UTC
[R] ggplot2 - value labels + "adjusting position using y instead"
I am building a horizontal bar plot using ggplot2 - see the code below.
A couple of questions:
1. On the right side of the graph the value labels are inside the bars. How
could I move them to be outside the bars - the way they are on the left
side?
2. How can I make sure that the scale on my X axis is such that I can
always the full value labels (even for the smallest or the largest values)?
3. What can I do to avoid the following warning: "ymax not defined:
adjusting position using y instead". My challenge is that I never now in
advance what the values of the chart will be. But I need to make a change
so that the warning does not need to come up.
Thanks a lot!
# My data set:
multiplier<-sample(c(1,2,10),20, replace=T)
set.seed(123)
DF <- data.frame(x = sample(LETTERS,20, replace = F),y=rnorm(20)*multiplier)
(DF)
# My plot:
library(ggplot2)
ggplot(DF, aes(x = factor(x,levels=rev(unique(x))),y=y)) +
geom_bar(stat="identity",fill="dark orange", color = NA,
alpha=1,position="identity")+
geom_text(aes(label=round(y,2)),colour="black",size=4,hjust=1.1,position='dodge')+
coord_flip()+
xlab("") +
ylab("")
--
Dimitri Liakhovitski
[[alternative HTML version deleted]]