Understanding How to Adjust the Width of ggbiplot Plots for PCA Results

Understanding ggbiplot for PCA Results: Why the Plot Width is Narrow and How to Adjust It

Introduction

Principal Component Analysis (PCA) is a widely used technique in data analysis, particularly in machine learning and statistics. One of the common visualization tools for PCA results is the biplot, which provides a comprehensive view of the variables and their relationships with the data points. The ggbiplot function in R is one such tool that allows us to create biplots using ggplot2. However, while ggplot2 plots can be adjusted to fit the desired plotting area, ggbiplot does not have this feature. In this article, we will explore why the plot width of a ggbiplot is narrow and how to adjust it.

What is ggbiplot?

ggbiplot is a function in R that creates biplots from PCA results using ggplot2. It provides an interactive visualization of the principal components, allowing users to rotate the axes, zoom in, and view individual data points. The function takes several arguments, including obs.scale, var.scale, ellipse, circle, varname.size, groups, and alpha.

How Does ggbiplot Create Biplots?

When creating a biplot using ggbiplot, the function first plots the data points according to their principal component values. Then, it overlays the variables as arrows from the origin of each variable to its corresponding data point.

## Code Block
P <- ggbiplot(pca.obj,
     obs.scale = 1, 
     var.scale=1,
     ellipse=T,
     circle=F,
     varname.size=3,
     groups=iris$Species, #no need for coloring, I'm making the points invisible
     alpha=0) #invisible points, I add them below

Why is ggbiplot’s Plot Width Narrow?

In ggplot2, plots can be adjusted to fit the desired plotting area using the coord_equal() function. However, in ggbiplot, this adjustment feature is not available.

## Code Block
P + coord_equal(ratio = 0.5)

As mentioned in the comments section of the Stack Overflow post, changing the aspect ratio of a plot can bias the interpretation of the length of the principal component vectors, which is why it’s set to 1 by default.

Adjusting ggbiplot’s Plot Width

To adjust the plot width of ggbiplot, you need to use the ratio argument in the coord_equal() function. By changing this value, you can control how the x and y units are scaled relative to each other.

## Code Block
P + coord_equal(ratio = 0.5)

By using a ratio of less than 1 (in this case, 0.5), we make the plot width larger, thus changing the aspect ratio of the plot.

Importance of Aspect Ratio in Biplots

When creating biplots, it’s crucial to consider the aspect ratio of the plot. The length of the principal component vectors can be affected by the aspect ratio of the plot, which is why changing the aspect ratio can affect the interpretation of the results.

## Code Block
# Changing the aspect ratio would bias the interpretation of the length of the principal component vectors,
# which is why it's set to 1.

Conclusion

In conclusion, while ggbiplot provides an interactive and comprehensive view of PCA results, its plot width cannot be adjusted using the same feature as ggplot2. However, by using the ratio argument in the coord_equal() function, we can control how the x and y units are scaled relative to each other, thus adjusting the plot width.

Additional Tips and Tricks

  • To make individual data points more visible, you can add them to a layer underneath the biplot. You can do this by adding geom_point(aes(color=iris$Species), cex=3) to the P$layers list.
  • To color the biplot based on groupings or categories, you can use the groups argument in the ggbiplot() function.
## Code Block
# Add geom_point in a layer underneath (only way I have to change the size of the points in ggbiplot)
P$layers <- c(geom_point(aes(color=iris$Species), cex=3), P$layers)

Final Thoughts

In this article, we discussed why the plot width of a ggbiplot is narrow and how to adjust it. We also explored the importance of aspect ratio in biplots and provided additional tips and tricks for customizing your ggbiplot results.

By following these steps and using the ratio argument in the coord_equal() function, you can create interactive and comprehensive biplots that accurately represent your data.

References

  • “ggbiplot: An extension of ggplot2 for plotting principal component analyses” by Thomas A. Kogner
  • Stack Overflow discussion on “How to adjust the aspect ratio in ggbiplot?”

Last modified on 2024-07-05