R重叠线图与ggplot在x轴上具有分类变量

R overlap line plots with ggplot with categorical variable on x-axis

我在尝试制作基本线图时遇到了一个我不明白的错误。我确定有一个简单的修复方法。这是我的 df(Chrom 有 24 个值,一些数字和一些字母)。

> df
# A tibble: 375 x 4
   Sample BasesCovered FractionOfTotal Chrom
   <chr>         <int>           <dbl> <chr>
 1 AE        169850837           0.682 1    
 2 BE        112368817           0.451 1    
 3 HE        116402736           0.468 1    
 4 C         142399396           0.572 1    
 5 AE:BE      93870879           0.377 1    
 6 AE:HE      98319854           0.395 1    
 7 AE:C      108852071           0.437 1    
 8 BE:HE      69040576           0.277 1    
 9 BE:C       72772760           0.292 1    
10 HE:C       74645628           0.300 1    
# ... with 365 more rows

这是我根据这个 line graph example

制作情节的代码

地块

ggplot(df, aes(y="FractionOfTotal", X="Chrom", group=1)) +
  geom_line(aes(colour="Sample"))

ggplot(df, aes(y="FractionOfTotal", X="Chrom")) +
 geom_line(aes(group=1))

ggplot(df, aes(y="FractionOfTotal", X="Chrom", colour="Sample")) +
  geom_line()

这些尝试中的每一个都会抛出此错误:

Error in order(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,  : 
  argument 3 is not a vector

我不确定参数 3 是什么?所以我试了这个没有帮助:

> is.vector(df$Sample)
[1] TRUE
> is.vector(df$Chrom)
[1] TRUE
> is.vector(df$FractionOfTotal)
[1] TRUE

我尝试搜索错误并找到 但在这种情况下,df 似乎有问题,我看不到在我的情况下是真的。

我确定这很简单?

除了我上面的评论之外,我实际上不确定您要绘制什么,但以下是有效的(请注意 aes 中的小写 x

ggplot(df, aes(y = FractionOfTotal, x = Chrom, group = 1)) +
    geom_line(aes(colour = Sample))


示例数据

df <- read.table(text =
    "   Sample BasesCovered FractionOfTotal Chrom
 1 AE        169850837           0.682 1
 2 BE        112368817           0.451 1
 3 HE        116402736           0.468 1
 4 C         142399396           0.572 1
 5 AE:BE      93870879           0.377 1
 6 AE:HE      98319854           0.395 1
 7 AE:C      108852071           0.437 1
 8 BE:HE      69040576           0.277 1
 9 BE:C       72772760           0.292 1
10 HE:C       74645628           0.300 1    ", header = T)