Define fortify and autoplot functions to allow ggplot2 to handle some popular R packages.

Overview
http://www.r-pkg.org/badges/version/ggfortify https://cranlogs.r-pkg.org/badges/grand-total/ggfortify https://coveralls.io/repos/sinhrks/ggfortify/badge.svg?branch=master&service=github

ggfortify

This package offers fortify and autoplot functions to allow automatic ggplot2 to visualize statistical result of popular R packages. Check out our R Journal paper for more details on the overall architecture design and a gallery of visualizations created with this package. Also check out autoplotly package that could automatically generate interactive visualizations with plotly.js style based on ggfortify. The generated visualizations can also be easily extended using ggplot2 syntax while staying interactive.

Note: For functions which returns list, ggfortify tries to infer a background class using its attribute names. Such functions are marked as "(inference)".

Installation

  • Install the latest stable release from CRAN:

    install.packages('ggfortify')
    
  • Install the development version from Github:

    if (!require("remotes")) install.packages("remotes")
    remotes::install_github('sinhrks/ggfortify')
    

Examples

Reference/Citation

To cite ggfortify in publications, please use (available via citation("ggfortify")):

Yuan Tang, Masaaki Horikoshi, and Wenxuan Li (2016). ggfortify: Unified Interface to Visualize Statistical Result of Popular R Packages. The R Journal, 8.2, 478-489.

Masaaki Horikoshi and Yuan Tang (2016). ggfortify: Data Visualization Tools for Statistical Analysis Results. https://CRAN.R-project.org/package=ggfortify

Coverage

This covers following classes:

  • base::matrix
  • base::table (supports fortify only)
  • cluster::clara
  • cluster::fanny
  • cluster::pam
  • cluster::silhouette
  • changepoint::cpt
  • dlm::dlmFilter
  • dlm::dlmSmooth (inference)
  • fGarch::fGARCH
  • forecast::bats
  • forecast::forecast
  • forecast::ets
  • forecast::nnetar
  • fracdiff::fracdiff
  • glmnet::cv.glmnet
  • glmnet::glmnet
  • KFAS::KFS
  • KFAS::signal (inference)
  • lfda::lfda
  • lfda::klfda
  • lfda::self
  • maps::map
  • MASS::isoMDS (inference)
  • MASS::sammon (inference)
  • raster::RasterBrick
  • raster::RasterCommon
  • raster::RasterLayer
  • raster::RasterStack
  • ROCR::performance
  • sp::Line
  • sp::Lines
  • sp::Polygon
  • sp::Polygons
  • sp::SpatialLines
  • sp::SpatialLinesDataFrame
  • sp::SpatialPoints
  • sp::SpatialPointsDataFrame
  • sp::SpatialPolygons
  • sp::SpatialPolygonsDataFrame
  • splines::basis
  • stats::acf
  • stats::ar
  • stats::Arima
  • stats::cmdscale (inference)
  • stats::decomposed.ts
  • stats::density
  • stats::factanal
  • stats::glm
  • stats::HoltWinters
  • stats::kmeans
  • stats::lm
  • stats::prcomp
  • stats::princomp
  • stats::spec
  • stats::stepfun
  • stats::stl
  • stats::ts
  • survival::survfit
  • survival::survfit.cox
  • survival::survfitms
  • strucchange::breakpoints
  • strucchange::breakpointsfull
  • timeSeries::timeSeries
  • tseries::irts
  • vars::varprd
  • xts::xts
  • zoo::zooreg

Helper Functions

  • ggdistribution to plot PDF/CDF
  • ggcpgram to plot cpgram
  • ggtsdiag to plot tsdiag
  • ggfreqplot to generalize monthplot

ggplot2 Families

There are some useful plotting packages using ggplot2. ggfortify will not focus on area already covered by these packages.

Comments
  • survfit error on plot

    survfit error on plot

    Hi,

    please, when i try to run

    library(ggfortify) library(survival) fit <- survfit(Surv(time, status) ~ sex, data = lung) autoplot(fit)

    gave this error: Error: GeomConfint was built with an incompatible version of ggproto. Please reinstall the package that provides this extension.

    thank you so much

    opened by fabioand2k 16
  • Keep order of factor levels.

    Keep order of factor levels.

    survfit from the survival package keeps the user's order of factor levels, but they become alphabetically reordered once ggfortify is used. This change keeps the levels in their original order.

    closes #142. closes #143.

    opened by DarioS 15
  • importing autoplot

    importing autoplot

    Dear Sir, I have written a function in which I used ggfortify to plot PCA the overall function is pretty simple, see below. When I do the package (https://github.com/kendomaniac/docker4seq) check I get the following warning: samplesPca: no visible global function definition for ‘autoplot’ Undefined global functions or variables: autoplot

    I import in my function ggfortify, but it seems that the autoplot in not imported from ggfortify Could please suggest a way of fix this problem? Cheers Raf

    ###################################### #' @title Sample PCA on raw counts #' @description This function runs PCA via ggfortify and ggplot2 on the output of samples2experiments function #' #' @param data, the counts dataframe generated by samples2experiemtn function #' @param groups, a character string indicating association between samples and experimental groups #' @param label, a boolean value, TRUE or FALSE to ad the names of the samples in the plot #' @param label.size, an integer value indicating the size of label #' @param output.file, a tab delimited file in which the first column are names from counts object from experiment.table.Rda file generated with samples2experiment function. In the pdf will be also rpesent the istigram fo the PCA variance dispersion. #' @import ggfortify #' @importFrom graphics plot #' @importFrom grDevices pdf #' @importFrom grDevices dev.off #' @importFrom stats prcomp #' @return a pdf file with the PCA plot #' @examples #'\dontrun{ #' load("test_experiment.tables.Rda") #' samplesPca(data=counts, groups=c("d","eb","wb","ws"), label = TRUE, label.size = 3) #' output.file="test.pdf", label = FALSE, label.size = 3) #' } #' @export samplesPca <- function(data, groups=NULL, output.file=NULL, label, label.size){ if(!is.null(groups)){ data.df <- data.frame(names(data), as.factor(groups)) names(data.df) <- c("samples","groups") if(is.null(output.file)){ autoplot.prcomp(prcomp(t(data)), data=data.df, colour='groups', label = label, label.size = label.size) }else{ pdf(output.file) plot(prcomp(t(data)), main="") autoplot(prcomp(t(data)), data=data.df, colour='groups', label = label, label.size = label.size) dev.off() cat(paste("\nPCA is saved in ",output.file, sep="")) } }else{ if(is.null(output.file)){ autoplot(prcomp(t(data))) }else{ pdf(output.file) plot(prcomp(t(data)), main="") autoplot(prcomp(t(data))) dev.off() cat(paste("\nPCA is saved in ",output.file, sep="")) } } return(data.df) }

    opened by kendomaniac 12
  • Remove label legend

    Remove label legend

    Hi,

    Thanks for the amazing package. Is there a way to remove label legend which is a small "a" in ggforty? Some parameters to work as geom_text(show.legend=F)? Thanks.

    Bests, oben

    opened by obenno 11
  • Package got removed from the CRAN

    Package got removed from the CRAN

    https://cran.r-project.org/web/packages/ggfortify/index.html shows:

    Package ‘ggfortify’ was removed from the CRAN repository.
    
    Formerly available versions can be obtained from the archive.
    
    Archived on 2016-05-02 as check problems were not corrected despite reminders.
    

    > install.packages fails as expected; however, the devtools install continues to work as expected after:

    library(devtools)
    install_github('sinhrks/ggfortify')
    
    opened by sciatro 10
  • ggsave doesn't recognize ggfortity objects

    ggsave doesn't recognize ggfortity objects

    plotdiag <-autoplot(result, which=c(1:3,5), mfrow=c(2,2)) plotdiag

    ***partdiage;

    ggsave(plot=plotdiag, file='cuckoo-R-diag.png', h=4, w=6, units="in", dpi=300)

    returns Error in UseMethod("grid.draw") : no applicable method for 'grid.draw' applied to an object of class "ggmultiplot"

    I think Wickham modifies ggsave() to accept gtable objects. Do you create such an object? Perhaps add that as a class as well?

    Using ggfortify 0.1.0 and ggplot 2.0.0

    opened by cschwarz-stat-sfu-ca 10
  • autoplot.lm() uses deprecated dplyr::arrange_()

    autoplot.lm() uses deprecated dplyr::arrange_()

    It appears that autoplot.lm() uses deprecated dplyr functions. This is a problem because dplyr is now throwing warnings about this and people using ggfortify on a daily basis for creating diagnostic plots shouldn't think that ggfortify has been abandoned.

    In particular lines 132, 136 and 140 in R/fortify_stats_lm.R use this to sort the fortified data by some column, but we can now just specify the arrangement without quoting desc(abs(.resid)). The same is true of the other instances.

    I cloned ggfortify and made the changes and it appears to work. However when I went to build the package, it seems that there are a bunch more dplyr deprecated function calls in the vignettes "basics.Rmd", "plot_pca.Rmd", "plot_surv.Rmd", "plot_ts.Rmd". I was reluctant to dive into all of those vignettes just to report this bug.

    I suspect that it wouldn't take to long to fix the vignettes, but I suspect this issue will touch a few other classes. I would be happy to start fixing those if it would be appreciated, but I didn't want to invest too much time before contacting people in charge.

    library(ggfortify) options(lifecycle_verbosity = 'error') # error out on deprecation warnings model <- lm( Volume ~ Height, data=trees) autoplot(model)

    The output (via reprex::reprex() ) is as follows:

    library(ggfortify) #> Loading required package: ggplot2 options(lifecycle_verbosity = 'error') model <- lm( Volume ~ Height, data=trees) autoplot(model) #> Error: arrange_() was deprecated in lifecycle 0.7.0 and is now defunct. #> Please use arrange() instead. #> See vignette('programming') for more help

    opened by dereksonderegger 8
  • Added support of survfitms

    Added support of survfitms

    Greetings.

    This PR adds support of survfitms - multistate survival models built using Surv(..., type = 'mstate').

    Here is an overview of changes to fortify:

    • To preserve original variable name depending on model class (surv or pstate) it is added to the end of the output data.frame;
    • Where necessary checks for variable name are made;
    • If surv.connect = T new rows are repeated according to number of states;
    • In the end columns are sorted to be in usual order.

    To autoplot:

    • Added facet_grid support - argument grid. It's more convenient for 2-dim set plots;
    • Added support to swap order of faceting (if facets) or column with rows (if grid). By default event first, then strata. Argument strip_swap;
    • An argument conf.int.group = NULL was added to plot_confint. It's required to split CI ribbons by both - event and strata, because it can't be done with fill only;
    • such artificial column group is assembled in autoplot.

    Feedback or questions are welcome.

    opened by yoursdearboy 7
  • Support survfit objects with multiple stratification variables. Fixes #214

    Support survfit objects with multiple stratification variables. Fixes #214

    In fortify_surv.R, changed the regular expression on line 49 to be "[^,]=" instead of ".=". This is in response to Issue #214, and the change is meant to allow autoplot to work on survfit objects with multiple stratification variables.

    testResults.txt

    opened by KellenBrosnahan 6
  • First try attempt at fortify & autoplot for spline basis objects

    First try attempt at fortify & autoplot for spline basis objects

    My attempt at #128. Unfortunately, I can't test it myself because the package fails devtools::check() with a nonsensical error message. It says:

    Installation failed.
    See ‘/private/var/folders/d3/ff25_6td3sjc02d8rfbwvmxc0000gn/T/RtmpxbR4VD/ggfortify.Rcheck/00install.out’ for details.
    

    And when I check the suggested log file, I see:

    * installing *source* package ‘ggfortify’ ...
    ** R
    ** inst
    ** preparing package for lazy loading
    ** help
    *** installing help indices
    ** building package indices
    ** installing vignettes
    ** testing if installed package can be loaded
    Warning: namespace ‘IRanges’ is not available and has been replaced
    by .GlobalEnv when processing object ‘’
    Warning in library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE,  :
      there is no package called ‘IRanges’
    Error in .requirePackage(package) :
      unable to find required package ‘IRanges’
    Error: loading failed
    Execution halted
    ERROR: loading failed
    * removing ‘/private/var/folders/d3/ff25_6td3sjc02d8rfbwvmxc0000gn/T/RtmpxbR4VD/ggfortify.Rcheck/ggfortify’
    

    I can't figure out why it's trying to load IRanges, and I can't figure out why it would be unable to do so, since I have it installed.

    opened by DarwinAwardWinner 6
  • COMPAT: Support ggplot2 1.1.0

    COMPAT: Support ggplot2 1.1.0

    Closes #67. Some changes are required for ggplot2 1.1.0 (dev). This works on my local with ggplot2 dev, still needs followings.

    • [x] Add a logic to distinguish ggplot2 version (and use previous logic for earlier vers...).
    • [x] Allow Travis to test 1.1.0 and earlier ggplot2 versions
    • ~~R CMD check with R dev version~~ Using R dev version is little hard to maintain dep packages. Skipped.
    opened by sinhrks 6
  • "colour" vs "color" when calling autoplot on a PCA

    When I follow your sample code to plot a PCA object, but call color= instead of colour=, the argument is ignored.

    library(ggfortify)
    library(cowplot)
    pca_res <- prcomp(iris[1:4], scale = TRUE)
    british <- autoplot(pca_res, data=iris, colour='Species')
    us <- autoplot(pca_res, data=iris, color='Species')
    plot_grid(british, us,  labels=c('colour', 'color'))
    
    

    I think this is the only time I've ever encountered a difference between the American and British spellings.

    > sessionInfo()
    R version 4.1.2 (2021-11-01)
    Platform: x86_64-w64-mingw32/x64 (64-bit)
    Running under: Windows 10 x64 (build 19044)
    
    Matrix products: default
    
    locale:
    [1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
    [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
    [5] LC_TIME=English_United States.1252    
    
    attached base packages:
    [1] stats     graphics  grDevices utils     datasets  methods   base     
    
    other attached packages:
    [1] cowplot_1.1.1    ggfortify_0.4.14 ggplot2_3.3.5  
    

    image3

    opened by lcmurtaugh 1
  • no x/y labels with ggdistribution plots

    no x/y labels with ggdistribution plots

    Hello,

    with the ggdistribution() function x and y labels do not appear.

    Code to reproduce the issue:

    p <- ggfortify::ggdistribution(dnorm, seq(-3, 3, 0.1), mean = 0, sd = 1)
    
    p <- p +
        labs(
        title = "Title",
        subtitle = "subtitle",
        caption = "name of the author copyright",
        tag = "Plot A",
        x = "x label",
        y = "y label"
    ) 
    p
    

    Plot produced by the code:

    xlab-problem


    System information

    • OS Platform and Distribution:macOS Monterey 12.1
    • ggfortify installed from (e.g. CRAN or Github): CRAN
    • ggfortify version: 0.4.14
    • ggplot2: 3.3.5
    • R: 4.1.2 (2021-11-01)

    Thanks, Peter

    opened by petzi53 12
  • Loadings cutoff option (PCA)

    Loadings cutoff option (PCA)

    Hello!

    First, thank you for developing the package, it has been very useful.

    I actually open an issue to request (if possible) a new feature at plotting the factor loadings in a PCA. There are already nice aesthetic options for the loadings. However, I would be interested on setting a loadings.cutoff option to select the desired ones. When working with PCAs based on many variables (50 in my case) it can become very messy even when playing with sizes and all. Furthermore, there are some factors that I may not be interested on, because they don't explain any variance in the samples, so it's also a nice feature to filter-out some factors.

    Thank you in advance.

    Regards, Cristian

    contributions welcome 
    opened by cdiazmun 5
  • how to change the confidence level

    how to change the confidence level

    I am trying to change the confidence level but conf.int.value gets ignored. Is there a workaround? No matter what level I put, it gets ignored.

    library(forecast) library(ggfortify) d.arima <- auto.arima(AirPassengers) autoplot(d.arima, predict=predict(d.arima,n.ahead=3),ts.colour = 'blue', predict.colour = 'blue', predict.linetype = 'dashed', conf.int = TRUE,conf.int.value=0.99)

    opened by FelipeCarrillo 7
  • Feature request: a method for the objects obtained from lmer, glmer of  package lme4

    Feature request: a method for the objects obtained from lmer, glmer of package lme4

    I have tried autoplot with ggfortify loaded for a model output of the function lmer of the package lme4. I have tried also ggfortify:::autoplot.lm applied to the model and did not work any of both options. It would be great if you could add a method for the class merMod (lmerMod, glmerMod).

    Thanks!

    enhancement contributions welcome 
    opened by iago-pssjd 0
Releases(v0.4.15)
Owner
Sinhrks
Sinhrks
The windML framework provides an easy-to-use access to wind data sources within the Python world, building upon numpy, scipy, sklearn, and matplotlib. Renewable Wind Energy, Forecasting, Prediction

windml Build status : The importance of wind in smart grids with a large number of renewable energy resources is increasing. With the growing infrastr

Computational Intelligence Group 125 Dec 24, 2022
Simulation du problème de Monty Hall avec Python et matplotlib

Le problème de Monty Hall C'est un jeu télévisé où il y a trois portes sur le plateau de jeu. Seule une de ces portes cache un trésor. Il n'y a rien d

ETCHART YANG 1 Jan 06, 2022
Create SVG drawings from vector geodata files (SHP, geojson, etc).

SVGIS Create SVG drawings from vector geodata files (SHP, geojson, etc). SVGIS is great for: creating small multiples, combining lots of datasets in a

Neil Freeman 78 Dec 09, 2022
Simple function to plot multiple barplots in the same figure.

Simple function to plot multiple barplots in the same figure. Supports padding and custom color.

Matthias Jakobs 2 Feb 21, 2022
A Bokeh project developed for learning and teaching Bokeh interactive plotting!

Bokeh-Python-Visualization A Bokeh project developed for learning and teaching Bokeh interactive plotting! See my medium blog posts about making bokeh

Will Koehrsen 350 Dec 05, 2022
Attractors is a package for simulation and visualization of strange attractors.

attractors Attractors is a package for simulation and visualization of strange attractors. Installation The simplest way to install the module is via

Vignesh M 45 Jul 31, 2022
A python package for animating plots build on matplotlib.

animatplot A python package for making interactive as well as animated plots with matplotlib. Requires Python = 3.5 Matplotlib = 2.2 (because slider

Tyler Makaro 394 Dec 18, 2022
Fastest Gephi's ForceAtlas2 graph layout algorithm implemented for Python and NetworkX

ForceAtlas2 for Python A port of Gephi's Force Atlas 2 layout algorithm to Python 2 and Python 3 (with a wrapper for NetworkX and igraph). This is the

Bhargav Chippada 227 Jan 05, 2023
A concise grammar of interactive graphics, built on Vega.

Vega-Lite Vega-Lite provides a higher-level grammar for visual analysis that generates complete Vega specifications. You can find more details, docume

Vega 4k Jan 08, 2023
Voilà, install macOS on ANY Computer! This is really and magic easiest way!

OSX-PROXMOX - Run macOS on ANY Computer - AMD & Intel Install Proxmox VE v7.02 - Next, Next & Finish (NNF). Open Proxmox Web Console - Datacenter N

Gabriel Luchina 654 Jan 09, 2023
Graphical display tools, to help students debug their class implementations in the Carcassonne family of projects

carcassonne_tools Graphical display tools, to help students debug their class implementations in the Carcassonne family of projects NOTE NOTE NOTE The

1 Nov 08, 2021
This is a small repository for me to implement my simply Data Visualisation skills through Python.

Data Visualisations This is a small repository for me to implement my simply Data Visualisation skills through Python. Steam Population Chart from 10/

9 Dec 31, 2021
Package managers visualization

Software Galaxies This repository combines visualizations of major software package managers. All visualizations are available here: http://anvaka.git

Andrei Kashcha 1.4k Dec 22, 2022
Interactive Dashboard for Visualizing OSM Data Change

Dashboard and intuitive data downloader for more interactive experience with interpreting osm change data.

1 Feb 20, 2022
An XLSX spreadsheet renderer for Django REST Framework.

drf-renderer-xlsx provides an XLSX renderer for Django REST Framework. It uses OpenPyXL to create the spreadsheet and returns the data.

The Wharton School 166 Dec 01, 2022
A python script to visualise explain plans as a graph using graphviz

README Needs to be improved Prerequisites Need to have graphiz installed on the machine. Refer to https://graphviz.readthedocs.io/en/stable/manual.htm

Edward Mallia 1 Sep 28, 2021
Practical-statistics-for-data-scientists - Code repository for O'Reilly book

Code repository Practical Statistics for Data Scientists: 50+ Essential Concepts Using R and Python by Peter Bruce, Andrew Bruce, and Peter Gedeck Pub

1.7k Jan 04, 2023
:bowtie: Create a dashboard with python!

Installation | Documentation | Gitter Chat | Google Group Bowtie Introduction Bowtie is a library for writing dashboards in Python. No need to know we

Jacques Kvam 753 Dec 22, 2022
ipyvizzu - Jupyter notebook integration of Vizzu

ipyvizzu - Jupyter notebook integration of Vizzu. Tutorial · Examples · Repository About The Project ipyvizzu is the Jupyter Notebook integration of V

Vizzu 729 Jan 08, 2023
Mattia Ficarelli 2 Mar 29, 2022