r - Adjust geom position along discrete scale -


i'm trying position text annotations on plot has both facets , discrete axis. can tie position of annotations points using aes(), i'd budge them little keep points readable. fine if nudge on numeric scale:

data <- data.frame(     category = c("blue", "yellow", "red", "green"),     rating = 1:4)  gp <- ggplot(data) + geom_point(aes(x = category, y = rating)) +     geom_text(aes(label = "i have label!", x = category, y = rating + 0.5)) 

but if try on non-numeric scale (in case, character) fails:

gp <- ggplot(data) + geom_point(aes(x = category, y = rating)) +     geom_text(aes(label = "i have label!", x = category + 0.5, y = rating)) gp  error in unit(x, default.units) : 'x' , 'units' must have length > 0 in addition: warning messages: 1: in ops.factor(category, 0.5) : + not meaningful factors 2: removed 4 rows containing missing values (geom_text). 

i use hjust , vjust move them little, since these designed align text rather position it, don't move annotations far enough away @ greatest extent. there way determine numeric scale maps discrete variable to, or way manually adjust geom_text's position?

you can use hjust (or vjust) position text:

ggplot(data) + geom_point(aes(x = category, y = rating)) +      geom_text(aes(label = "i have label!", x = category, y = rating), hjust=-.1) 

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -