medo 一个不漂亮的画法:
library(ggplot2)
x <- seq(0.1, 10, by = 0.1)
z <- c(1, 2, 3, 4)
y1 <- z[1]/x
y2 <- z[2]/x
y3 <- z[3]/x
y4 <- z[4]/x
z <- rep(c("z1", "z2", "z3", "z4"), each = 100)
x <- rep(x, 4)
y <- c(y1, y2, y3, y4)
df <- data.frame(z, x, y)
ggplot(df, aes(x = x, y = y, color = z)) + geom_line() +
coord_cartesian(ylim = c(0, 10), expand = F)
要是其他成员有比较好的方法,希望能学习一下。
受大鹏启发,精简一下:
library(ggplot2)
x <- seq(0.1, 10, by = 0.1)
z <- rep(1:4, each = 100)
df <- data.frame(x, y = z/x, z = factor(z))
ggplot(df, aes(x = x, y = y, color = z)) + geom_line() +
coord_cartesian(ylim = c(0, 10), expand = F)
给自己的笔记:产生数据组合,可以用 expand.grid()
。