Hi all,

I have bulk RNA-seq data with 12 samples - WT (x4), 'A' KO (x4), and 'B' KO (x4). I want to generate a 2D PCA plot (biplot) like below figure to look at the relationship between the samples. 

![a 2D PCA plot][1]

I have tried an R package, 'PCAtools,' but it looks not work correctly as below. 
![the PCA plot generated by the code below][2]


I have pasted my code and data below. I will very much appreciate it if you share any advice or suggestions.

Thanks in advance!

Joshua



    library(PCAtools)
    data <-read.csv("C:/.../all,gene_log2cpm_revised.csv", fileEncoding = 'UTF-8-BOM')

    groups = c(rep("WT", 4), rep("A-KO", 4), rep("B-KO", 4))
    cols = c('red', 'green', 'blue')[factor(groups)]

    data$gene_name = as.numeric(as.factor(data$gene_name))

    pca = prcomp(data)
    pca$x
    pca$sdev
    biplot(pca, cex=0.7, scale=T, xlim=c(-0.6,+0.6))

Data file format:

![Data file format top genes][3]


  [1]: /media/images/7893d708-b043-4fc5-a698-665c99df
  [2]: /media/images/428ae629-d824-4fc0-a2a2-9c61f108
  [3]: /media/images/a9d95265-adc6-444c-9aca-17b400a3
Hi Joshua,

Your second plot is not produced by my package, *PCAtools*. It is produced via base R functions.

Can you take a look through my vignette, please? - https://bioconductor.org/packages/release/bioc/vignettes/PCAtools/inst/doc/PCAtools.html#quick-start-deseq2

You probably need something like:

    library(PCAtools)
    data <- read.csv(
      'C:/.../all,gene_log2cpm_revised.csv',
      fileEncoding = 'UTF-8-BOM',
      row.names = 1)
    
    groups = c(rep("WT", 4), rep("A-KO", 4), rep("B-KO", 4))
    cols = c('red', 'green', 'blue')[factor(groups)]

    metadata <- data.frame(groups = groups)
    rownames(metadata) <- colnames(data)
    p <- pca(data, metadata = metadata)

    biplot(p, colby = 'groups')

Kevin
