inst/examples/matplot2-tikz.R

# ggplot2 画出的一系列正弦曲线
sines = outer(1:20, 1:4, function(x, y) sin(x / 20 * pi * y))
df = expand.grid(x = 1:20, y = factor(1:4))
df$sines = as.vector(sines)
p = ggplot(df, aes(x = x, y = sines, color = y)) +
  geom_point(aes(shape = y)) +
  geom_line() +
  labs(x = "$x$") +
  guides(col = guide_legend("$y$"), shape = guide_legend("$y$") )
print(p)
yihui/MSG documentation built on Aug. 16, 2021, 12:13 p.m.