5

Say this is my dataset:

> ( fake = data.frame( id=as.character(18:22), x=rnorm(5), y=rnorm(5) ) )

  id           x           y
1 18  1.93800377  0.67515777
2 19  1.28241814 -0.04164806
3 20 -1.58919444 -0.50885536
4 21 -0.08127943 -1.90003188
5 22  0.78134213  0.17693039

I want a scatterplot of x vs. y in which the plotting shape is the id variable. I tried this:

ggplot( data=fake, aes( x=x, y=y, shape=id) ) + geom_point() +
  scale_shape_manual(values=as.character(fake$id)) + theme_bw()

enter image description here

It appears that only the first character of id is being used as a plotting shape. How can I use the entire string?

1 Answer 1

9

If you want to print text on a plot, use geom_text rather than geom_point

ggplot( data=fake, aes( x=x, y=y, label=id) ) + geom_text() + theme_bw()

The plotting character (shape) used by geom_point can only be a single character. For longer strings, you must use geom_text().

enter image description here

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

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.