0

I am trying to add the label of a number above geom_point using geom_text with no success. I want to show the calories intake of each fruit. It is clear on the x-axis, but i would like to write the label of each number above the dot point in the plot. Could someone help please?

enter image description here

Here is the data and the code:

df= structure(list(fruit = structure(1:3, .Label = c("Orange", "Banana", 
                                                     "Kiwi"), class = "factor"), term = c("calories", "calories", "calories"), 
                   calories = c(47, 89, 61
                   )), row.names = c(NA, -3L), class = "data.frame")


df %>%
  ggplot(aes(calories, fruit)) + 
  geom_point(mapping=aes(x=calories, y=fruit), size=5) 
Jack
  • 813
  • 4
  • 17

1 Answers1

2

I think geom_label() will do the job.

ggplot(data = df, aes(x = calories, y = fruit)) + 
  geom_point(size=5) + 
  geom_label(label = df$calories)

You can use the nudge_x and nudge_y arguments to set where the labels go in relation to the point.

Tob
  • 245
  • 1
  • 9