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()

It appears that only the first character of id is being used as a plotting shape. How can I use the entire string?
The function geom_point() adds a layer of points to your plot, which creates a scatterplot.
geom_line() connects them in order of the variable on the x axis. geom_step() creates a stairstep plot, highlighting exactly when changes occur. The group aesthetic determines which cases are connected together.
Aesthetic Mapping ( aes ) In ggplot2 , aesthetic means “something you can see”. Each aesthetic is a mapping between a visual cue and a variable. Examples include: position (i.e., on the x and y axes) color (“outside” color)
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().

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With