PCA Graphing Outputs

46 views
Skip to first unread message

Jeff Pashnick

unread,
Mar 9, 2014, 4:50:26 PM3/9/14
to ggp...@googlegroups.com
Hello All,

I've made the following PCA graph (first attachment), but, I'd like to modify it further and I have some things I want to show while keeping the current look (colors of each points, legend, etc.)
I'm attempting to show vectors such as in another plot I've made (second attachment) and also have the points labeled with the names in the legend from the first plot.

Here is the code I've used to this point:
library(reshape2)
library(ggplot2)
library(grid)
# Load in the Data #
hapfreq <-read.csv('Hapfreq4.csv', header=T)
hapfreq
#Subset for PCA#
hgf<-subset(hapfreq, select=C:K)
hgf
#Run the PCA#
pca <- prcomp(hgf, scale=T)
summary (pca)
pca
###Graphing the PCA####
# This is the hard part. Going to try using the ggplot2 library###
scores <- data.frame(hgf, pca$x[,1:2])
scores
hapfreq2 <-read.csv('abb1.csv', header=T)
hapfreq3 <-read.csv('HGs.csv', header=T)
jphg <- data.frame(scores, hapfreq2)
jphg
pcaplot <- qplot(x=PC1, y=PC2, data=jphg, colour=factor(abbr.))
pcaplot

Hopefully this makes sense. Let me know if you have questions and thanks in advance for the help.
PCAcolor.jpeg
PCA1test_03082014JP.jpeg

Vivek Patil

unread,
Mar 11, 2014, 8:15:03 AM3/11/14
to Jeff Pashnick, ggplot2
Can you provide a reproducible example? This discussion on SO should help: http://stackoverflow.com/questions/6578355/plotting-pca-biplot-with-ggplot2



--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages