与R的线图

use*_*557 -1 plot r ggplot2

这不应该是这么难,但我被困住了.我有一个以下表格的表格:

        |   1     |   2    |   3
  ------------------------------------
  TypeA |  3213   |  2121  |   43    
  TypeB |  31321  |  321   |   10
  TypeC |  332    |   11   |   9
Run Code Online (Sandbox Code Playgroud)

我想生成一条线图,有三条线:每条Type一条,x坐标为"1,2,3",y坐标为数字(3213,...).我按照这里的步骤操作,但不知道如何迭代第一列.

Rom*_*rik 5

如果添加另一列在x轴上定义它们的值,则可以使用tidyr::gather并使用它来绘制数据geom_line.theme_bw()是否有删除灰色背景.

xy <- data.frame(type = c("a", "b", "c"), one = runif(3), 
                 two = runif(3), three = runif(3), seq = 1:3)

library(tidyr)

xyg <- gather(data = xy, typ, val, -seq, -type)

library(ggplot2)

ggplot(xyg, aes(x = seq, y = val, color = typ)) +
  theme_bw() +
  geom_line()
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述