Reputation: 12321
I am using geom_line
, geom_point
, and geom_text
to plot something like the picture below:
I am grouping, and coloring my data frame, but I want the geom_text
not to be so close to each other.
I want to put the one text on top, and the other on bottom. Or at least, hide the one of the two. Is there any way I can do this?
Upvotes: 1
Views: 4850
Reputation: 4282
You can specify custom aesthetics in different geom_text()
calls. You can include only a subset of the data (such as just one group) in each call, and give each geom_text()
a custom hjust
or vjust
value for each subset.
ggplot(dat, aes(x, y, group=mygroups, color=mygroups, label=mylabel)) +
geom_point() +
geom_line() +
geom_text(data=dat[dat$mygroups=='group1',], aes(vjust=1)) +
geom_text(data=dat[dat$mygroups=='group2',], aes(vjust=-1))
Upvotes: 6