rplotggplot2ggfortify

Reproducing stats::biplot with ggplot2::autoplot from ggfortify R package


I'm trying to reproduce the following stats::biplot plot with ggplot2::autoplot from ggfortify R package.

biplot(prcomp(USArrests, scale = TRUE))

enter image description here

Here is my ggplot2::autoplot code from ggfortify R package with its output.

devtools::install_github("sinhrks/ggfortify")
 library(ggfortify)
ggplot2::autoplot(stats::prcomp(USArrests, scale=TRUE), label = TRUE, loadings.label = TRUE)

enter image description here

Questions

  1. Why the two plots are different? How to reproduce the base plot?
  2. How to add labels as shown in base plot?

Solution

  • Thank you for using the package. The issue is depending on {dplyr} version, and being fixed in {ggfortify}. Could you update the package and then try?

    I've attached the result after the fix to below link:

    https://github.com/sinhrks/ggfortify/pull/21