1

Here is my example:

a <- data.frame(X=c(1,2,3,4,5),Y=c(1,2,3,4,5),A1=c(1,2,3,4,5),A2=c(6,7,8,9,10))

A1 and A2 are two types of annotation. Now I only can add one annotation into the plot.

library(ggplot2)
ggplot(data=a,aes(x=X,y=Y,label=A1)) +
      geom_point() +
      geom_text(hjust=0,vjust=-1)

Can I put A1 and A2 into the plot? So it looks like A1 and A2 are one the same vertical line, and A1 is on top of A2?

2 Answers 2

1

You can use different geom_text:

library(ggplot2)
ggplot(a,aes(X, Y)) +
      geom_point() +
      geom_text(aes(label = A1), ahjust = 0, vjust = -2.5) +
      geom_text(aes(label = A2), ahjust = 0, vjust = -1) +
      ylim(c(min(a$Y), max(a$Y) + 1))

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

1

You can use paste in label

ggplot(data=a,aes(x=X,y=Y,label=paste(A1,A2, sep = ","))) + geom_point() + geom_text(hjust=0,vjust=-1)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.