-4

我有简单的数据:

DATA1   DATA2   DATA3
1        20%    25%
2        27%    32%
3        40%    28%
4        37%    24%
5        42%    20%
6        45%    19%
7        70%    20%

结果,我想构建PLOT x = DATA1两行带有数据标签的行1

以最好的方式,我想控制шт应该用百分比设置标签。谢谢

4

2 回答 2

0

您需要将 DATA2 和 DATA3 组合到一个向量并创建一个向量来定义您的数据。

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 = "")))
于 2018-10-24T07:30:28.863 回答
0

如果您提供了一个可重现的示例,这将有所帮助,但我认为您想要这样的东西:

data <- data.frame(
  DATA1 = 1:7,
  DATA2 = c(20, 27, 40, 37, 42, 45, 70), 
  DATA3 = c(25,32,28,24,20,19,20))

ggplot(data=data, aes(DATA1, DATA2)) +
    geom_line() + 
    geom_label (label = DATA2) +
    geom_line (data=data, aes(DATA1, DATA3)) +
    geom_label (data=data, aes(DATA1, DATA3), label=DATA3) +
    ylab ("%")
于 2018-10-24T07:44:43.103 回答