<p>Maybe try</p>

<pre><code>plot(evecdat$PC1, evecdat$PC2, xlab="PC1", ylab="PC2", pch="24", cex.lab=2.5, cex.axis=1, type="n")  
text(evecdat$PC1, evecdat$PC2, evecdat$Sample, col=as.vector(evecdat$color))
</code></pre>

<p>This should plot the sample names as text (taken from the <code>evecdat$Sample</code> column), colored as specified in the <code>evecdat$color</code> column. See <code>?text</code> for details.</p>

CC BY-SA 4.0
2018-09-13T14:37:15.013Z
2018-09-13T14:37:15.013Z
Pascal Martin
<p>I made a PCA plot and was trying to plot the eigenvenctors in R so that each data point is actually the sample name. All the samples are in column 1. The following are the R commands I am using:</p>

<pre><code>    fn &lt;- "Plot.txt"
    evecdat &lt;- read.table(fn, col.names=c("Sample", "PC1", "PC2", "PC3", "PC4", "PC5", "PC6", "PC7", "PC8", "PC9", "PC10", "pc11","pc12", "pc13", "pc14", "pc15","pc16", "pc17", "pc18", "pc19", "pc20", "pop", "color"))
    jpeg("Plot1.jpeg", width = 20, height = 20, units = 'in', res = 300)
    identify(evecdat$PC1, evecdat$PC2  = NULL, labels = seq_along(evecdat$Sample), pos = TRUE, n = length(evecdat$Sample), plot = FALSE, atpen = FALSE, offset = 0.5, tolerance = 0.25, …)

    plot(evecdat$PC1, evecdat$PC2, col=as.vector(evecdat$color), xlab="PC1", ylab="PC2", pch="24", cex.lab=2.5, cex=1.5, cex.axis=1)
    legend("topright", ncol=1, legend=c("X", "Y", "Z"), col=c("Blue", "Red", "Green"), pch="24", cex=2, bty = "o")
    while (!is.null(dev.list())) dev.off()
</code></pre>

<p>Here, all the row names are under the Sample column name that I defined earlier. </p>

CC BY-SA 4.0
2018-09-12T07:39:57.717Z
We don't have the "Plot.txt" data file so we can't test, but what problem do you have with the code? You get the plot without the name of the samples? Have you looked at  `text`?
llrs
<bioconductor><ggplot2><pca>
Error in annotating row names as data points in a PCA plot
# Error in annotating row names as data points in a PCA plot

(Asked by: username_0 on 2018-09-11)

I made a PCA plot and was trying to plot the eigenvenctors in R so that each data point is actually the sample name. All the samples are in column 1. The following are the R commands I am using:
    fn <- "Plot.txt"
    evecdat <- read.table(fn, col.names=c("Sample", "PC1", "PC2", "PC3", "PC4", "PC5", "PC6", "PC7", "PC8", "PC9", "PC10", "pc11","pc12", "pc13", "pc14", "pc15","pc16", "pc17", "pc18", "pc19", "pc20", "pop", "color"))
    jpeg("Plot1.jpeg", width = 20, height = 20, units = 'in', res = 300)
    identify(evecdat$PC1, evecdat$PC2  = NULL, labels = seq_along(evecdat$Sample), pos = TRUE, n = length(evecdat$Sample), plot = FALSE, atpen = FALSE, offset = 0.5, tolerance = 0.25, …)

    plot(evecdat$PC1, evecdat$PC2, col=as.vector(evecdat$color), xlab="PC1", ylab="PC2", pch="24", cex.lab=2.5, cex=1.5, cex.axis=1)
    legend("topright", ncol=1, legend=c("X", "Y", "Z"), col=c("Blue", "Red", "Green"), pch="24", cex=2, bty = "o")
    while (!is.null(dev.list())) dev.off()

Here, all the row names are under the Sample column name that I defined earlier.

**Tags:** bioconductor, ggplot2, pca
> **Comments:**
> **username_1**: We don't have the "Plot.txt" data file so we can't test, but what problem do you have with the code? You get the plot without the name of the samples? Have you looked at  `text`?  

---

## 1 answers

### Answer by username_2 on 2018-09-13. Score: 2

Maybe try
plot(evecdat$PC1, evecdat$PC2, xlab="PC1", ylab="PC2", pch="24", cex.lab=2.5, cex.axis=1, type="n")  
text(evecdat$PC1, evecdat$PC2, evecdat$Sample, col=as.vector(evecdat$color))

This should plot the sample names as text (taken from the evecdat$Sample column), colored as specified in the evecdat$color column. See ?text for details.


---

