[Solved] R (ggplot2): line with data labels [closed]


You need to combine DATA2 and DATA3 to one vector and create a vector to define your data.

library(ggplot2)
x1 <- c(0.2, 0.27, 0.4, 0.37, 0.42, 0.45, 0.70)
x2 <- c(0.25, 0.32, 0.28, 0.24, 0.20, 0.19, 0.20)

data <- data.frame(x = rep(c(1:7), 2), label = rep(c("x1", "x2"),  each = 7), y = c(x1, x2))


ggplot(data = data, aes(x = x)) +
  geom_line(data = data, aes(x = x, y = y, col = label))+
  geom_text(data = data, aes(y = y, label = paste(y*100, "%", sep = "")))

solved R (ggplot2): line with data labels [closed]