agenis - 1 year ago 116

R Question

I want to plot the result of a PCA with the package factominer. When one plots a PCA it is good practice to resize the graph so that its H/L ratio is in proportion to the %variance explained by each axis.

So I tried first to resize the graph simply by stretching the window: it obviously fails and keep the points in the middle **instead of stretching them too.**

`library(FactoMineR)`

out <- PCA(mtcars)

Then I try to force the

`xlim`

`ylim`

`?plot.PCA`

`plot.PCA(out, choix="ind", xlim=c(-6,6), ylim=c(-4, 4))`

Same problem, the xlim limits are not respected...

Can someone explain this behaviour and knows how to fix it?

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

What you're seeing is the result of the call to `plot`

inside `plot.PCA`

:

```
plot(0, 0, main = titre, xlab = lab.x, ylab = lab.y,
xlim = xlim, ylim = ylim, col = "white", asp = 1, ...)
```

`plot`

is called with parameter `asp`

set to `1`

, which guarantees that the *y/x* ratio stays the same, so when you try to resize the window, the `xlim`

are recomputed.

In `plot.window`

you can find the "meaning" of `asp`

:

If asp is a finite positive value then the window is set up so that one data unit in the x direction is equal in length to asp * one data unit in the y direction.

You can try

```
plot(0, 0, main = "", xlab = "", ylab = "", xlim = c(-6, 6), ylim = c(-4, 4), col = "white", asp = 1)
```

and resizing the window, and then the same with

```
plot(0, 0, main = "", xlab = "", ylab = "", xlim = c(-6, 6), ylim = c(-4, 4), col = "white")
```

to see the difference.