Alexis
Alexis

Reputation: 2294

Ignoring unknown aesthetics: text in ggplot (using numbers or letters as points)

I have this dataset:

library(tidyverse)
dataset <- data.frame(CustomerId = c(1,2),
                      umap_01 = c(0.0198, -0.319),
                      umap_02 = c(0.336, -0.321))

And I want to create a ggplot with this code:

p <- dataset %>%
  ggplot(aes(umap_01,umap_02)) +
  geom_point(aes(text = CustomerId), alpha = 0.5)

But I received this message:

Warning message:
Ignoring unknown aesthetics: text 

I don't understand why if text is a valid aesthetic. Please, could you help me this code? What I am doing wrong?

Upvotes: 2

Views: 1010

Answers (2)

tjebo
tjebo

Reputation: 23717

another option is to use shape. If you pass a column of your data into aes, you'd need to use either scale_shape_identity or I().

library(tidyverse)
dataset <- data.frame(CustomerId = c(1,2),
                      umap_01 = c(0.0198, -0.319),
                      umap_02 = c(0.336, -0.321))
dataset %>%
  ggplot(aes(umap_01,umap_02)) +
  geom_point(aes(shape = I(as.character(CustomerId))), size = 10, alpha = 0.5) 

Created on 2021-04-30 by the reprex package (v2.0.0)

Upvotes: 3

bird
bird

Reputation: 3294

You can use geom_text. For example:

p <- dataset %>%
        ggplot(aes(umap_01,umap_02, label = CustomerId)) +
        geom_text(alpha = 0.5)
p

enter image description here

Upvotes: 2

Related Questions