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
A programming language built on top of Python to easily allow Swahili speakers to get started with programming without ever knowing English

pyswahili A programming language built over Python to easily allow swahili speakers to get started with programming without ever knowing english pyswa

Jordan Kalebu 72 Dec 15, 2022
Wikipedia WordCloud App generate Wikipedia word cloud art created using python's streamlit, matplotlib, wikipedia and wordcloud packages

Wikipedia WordCloud App Wikipedia WordCloud App generate Wikipedia word cloud art created using python's streamlit, matplotlib, wikipedia and wordclou

Siva Prakash 5 Jan 2, 2022
A Python library created to assist programmers with complex mathematical functions

libmaths was created not only as a learning experience for me, but as a way to make mathematical models in seconds for Python users using mat

Simple 73 Oct 2, 2022
3D Vision functions with end-to-end support for deep learning developers, written in Ivy.

Ivy vision focuses predominantly on 3D vision, with functions for camera geometry, image projections, co-ordinate frame transformations, forward warping, inverse warping, optical flow, depth triangulation, voxel grids, point clouds, signed distance functions, and others. Check out the docs for more info!

Ivy 61 Dec 29, 2022
Functions for easily making publication-quality figures with matplotlib.

Data-viz utils ?? Functions for data visualization in matplotlib ?? API Can be installed using pip install dvu and then imported with import dvu. You

Chandan Singh 16 Sep 15, 2022
Function Plotter: a simple application with GUI to plot mathematical functions

Function-Plotter Function Plotter is a simple application with GUI to plot mathe

Mohamed Nabawe 4 Jan 3, 2022
Some problems of SSLC ( High School ) before outputs and after outputs

Some problems of SSLC ( High School ) before outputs and after outputs 1] A Python program and its output (output1) while running the program is given

Fayas Noushad 3 Dec 1, 2021
Some examples with MatPlotLib library in Python

MatPlotLib Example Some examples with MatPlotLib library in Python Point: Run files only in project's directory About me Full name: Matin Ardestani Ag

Matin Ardestani 4 Mar 29, 2022
Some useful extensions for Matplotlib.

mplx Some useful extensions for Matplotlib. Contour plots for functions with discontinuities plt.contour mplx.contour(max_jump=1.0) Matplotlib has pro

Nico Schlömer 519 Dec 30, 2022
Some method of processing point cloud

Point-Cloud Some method of processing point cloud inversion the completion pointcloud to incomplete point cloud Some model of encoding point cloud to

Tan 1 Nov 19, 2021
Visualizations of some specific solutions of different differential equations.

Diff_sims Visualizations of some specific solutions of different differential equations. Heat Equation in 1 Dimension (A very beautiful and elegant ex

null 2 Jan 13, 2022
Drug design and development team HackBio internship is a virtual bioinformatics program that introduces students and professional to advanced practical bioinformatics and its applications globally.

-Nyokong. Drug design and development team HackBio internship is a virtual bioinformatics program that introduces students and professional to advance

null 4 Aug 4, 2022
The Timescale NFT Starter Kit is a step-by-step guide to get up and running with collecting, storing, analyzing and visualizing NFT data from OpenSea, using PostgreSQL and TimescaleDB.

Timescale NFT Starter Kit The Timescale NFT Starter Kit is a step-by-step guide to get up and running with collecting, storing, analyzing and visualiz

Timescale 102 Dec 24, 2022
Plot and save the ground truth and predicted results of human 3.6 M and CMU mocap dataset.

Visualization-of-Human3.6M-Dataset Plot and save the ground truth and predicted results of human 3.6 M and CMU mocap dataset. human-motion-prediction

Gaurav Kumar Yadav 5 Nov 18, 2022
Debugging, monitoring and visualization for Python Machine Learning and Data Science

Welcome to TensorWatch TensorWatch is a debugging and visualization tool designed for data science, deep learning and reinforcement learning from Micr

Microsoft 3.3k Dec 27, 2022
Visualize and compare datasets, target values and associations, with one line of code.

In-depth EDA (target analysis, comparison, feature analysis, correlation) in two lines of code! Sweetviz is an open-source Python library that generat

Francois Bertrand 2.3k Jan 5, 2023
Visualize and compare datasets, target values and associations, with one line of code.

In-depth EDA (target analysis, comparison, feature analysis, correlation) in two lines of code! Sweetviz is an open-source Python library that generat

Francois Bertrand 1.2k Feb 18, 2021
Smoking Simulation is an app to simulate the spreading of smokers and non-smokers, their interactions and population during certain amount of time.

Smoking Simulation is an app to simulate the spreading of smokers and non-smokers, their interactions and population during certain

Bohdan Ruban 5 Nov 8, 2022
Rubrix is a free and open-source tool for exploring and iterating on data for artificial intelligence projects.

Open-source tool for exploring, labeling, and monitoring data for AI projects

Recognai 1.5k Jan 7, 2023