# import library ggplot2
library(ggplot2)
# Create dataset
x1 <- c(1, 1, 1, 2, 3, 4, 4, 4, 5, 5, 6, 2, 3)
y1 <- c(7, 23, 31, 14, 11, 3, 13, 27, 21, 10, 21, 14, 30)
label1 <- c('Apple', 'Guava', 'Papaya', 'Orange', 'PineApple',
'Dragon Fruit', 'Kiwi', 'blackberry', 'blueberry',
'grapes', 'strawberry', 'raspberry', 'Grapefruit')
sample_data <- data.frame(x1, y1, label1)
# add text with geom_text
ggplot(sample_data, aes(x=x1, y=y1)) +
geom_point() +
geom_label(
label=label1,
nudge_x=0.45, nudge_y=0.1,
check_overlap=T,
label.padding=unit(0.55, "lines"),
label.size=0.4,
color="white",
fill="#038225"
)