我有简单的数据:
DATA1 DATA2 DATA3
1 20% 25%
2 27% 32%
3 40% 28%
4 37% 24%
5 42% 20%
6 45% 19%
7 70% 20%
以最佳方式,我想控制应设置百分比的标签的交集。 谢谢
答案 0 :(得分: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 = "")))
答案 1 :(得分: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 ("%")