# plot PCA projection: How interpret

**URL:** <https://discourse.julialang.org/t/plot-pca-projection-how-interpret/9966>\
**Category:** New to Julia\
**Tags:** question, package, plotting, pyplot, packages\
**Created:** [March 25, 2018, 2:34pm UTC](https://discourse.julialang.org/t/plot-pca-projection-how-interpret/9966 "2018-03-25T14:34:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ana](https://avatars.discourse-cdn.com/v4/letter/a/a6a055/32.png) [@Ana](https://discourse.julialang.org/u/Ana)\
**Post date:** [March 25, 2018, 2:34pm UTC](https://discourse.julialang.org/t/plot-pca-projection-how-interpret/9966/1 "2018-03-25T14:34:01Z")

</div>

I want to perform PCA on my data\_array object.  
How do I get a nice plot of the data projected onto the first two principal components?

I tried

```julia
using ManifoldLearning
using Plots

M1 = fit(PCA, data_array; maxoutdim=2)
# transforms observations data_array into PCs
Y1 = transform(M1, data_array) # 2x547
X_PCA = reconstruct(M1, Y1) # 96x547
M1_proj = projection(M1) # 96x2

Plots.scatter(M1_proj, title="PCA projection", legend=false)

```

but I cannot quite interpret the plot… It does not look any like standard PCA projection plots.

Any ideas?

---

<div class="post-metadata">

**Author:** ![gdkrmr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdkrmr/32/2791_2.png) [@gdkrmr](https://discourse.julialang.org/u/gdkrmr)\
**Post date:** [March 25, 2018, 2:39pm UTC](https://discourse.julialang.org/t/plot-pca-projection-how-interpret/9966/2 "2018-03-25T14:39:46Z")

</div>

you are plotting the rotation matrix, which is usually plotted as arrows in a biplot (see [here](https://support.sas.com/documentation/cdl/en/statug/63347/HTML/default/images/prqib.png) for an example), you have to plot Y1 for the actual points.

---

<div class="post-metadata">

**Author:** ![Ana](https://avatars.discourse-cdn.com/v4/letter/a/a6a055/32.png) [@Ana](https://discourse.julialang.org/u/Ana)\
**Post date:** [March 25, 2018, 4:02pm UTC](https://discourse.julialang.org/t/plot-pca-projection-how-interpret/9966/3 "2018-03-25T16:02:10Z")

</div>

Thanks! I just realised it is Y1. However, how can I plot the rotation matrix, or rather the new directions in the old coordinate system ?

---

<div class="post-metadata">

**Author:** ![gdkrmr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdkrmr/32/2791_2.png) [@gdkrmr](https://discourse.julialang.org/u/gdkrmr)\
**Post date:** [March 25, 2018, 8:16pm UTC](https://discourse.julialang.org/t/plot-pca-projection-how-interpret/9966/4 "2018-03-25T20:16:02Z")

</div>

You use the rotation matrix as coordinates for the arrow tips, all arrows start from the origin. You may have to scale them, so they fit nicely into your data.

---

<div class="post-metadata">

**Author:** ![Ana](https://avatars.discourse-cdn.com/v4/letter/a/a6a055/32.png) [@Ana](https://discourse.julialang.org/u/Ana)\
**Post date:** [March 26, 2018, 1:53am UTC](https://discourse.julialang.org/t/plot-pca-projection-how-interpret/9966/5 "2018-03-26T01:53:40Z")

</div>

Thanks, yes, I know. That is my question. I can’t find the right package/function.

---

<div class="post-metadata">

**Author:** ![gdkrmr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdkrmr/32/2791_2.png) [@gdkrmr](https://discourse.julialang.org/u/gdkrmr)\
**Post date:** [March 26, 2018, 8:09am UTC](https://discourse.julialang.org/t/plot-pca-projection-how-interpret/9966/6 "2018-03-26T08:09:04Z")

</div>

For serious plotting I still use `RCall`, depending on where you come from you might want to consider `PyPlot` too.
