How to make scatter plot points into numbers?

Viewed 483

I am creating a scatter plot using ggplot/geom_point. Here is my code for building the function in ggplot.

AddPoints <- function(x) {
    list(geom_point(data = dat , mapping =  aes(x = x, y = y) , shape = 1 , size = 1.5 ,
color = "blue"))
} 

I am wondering if it would be possible to replace the standard points on the plot with numbers. That is, instead of seeing a dot on the plot, you would see a number on the plot to represent each observation. I would like that number to correspond to a column for that given observation (column name 'RP'). Thanks in advance.

Sample data.

 Data <- data.frame(
    X = sample(1:10),
     Y = sample(3:12),
    RP = sample(c(4,8,9,12,3,1,1,2,7,7)))
1 Answers

Use geom_text() and map the rp variable to the label argument.

ggplot(Data, aes(x = X, y = Y, label = RP)) +
  geom_text()
Related