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
Quickly and accurately render even the largest data.

Turn even the largest data into images, accurately Build Status Coverage Latest dev release Latest release Docs Support What is it? Datashader is a da

HoloViz 2.9k Dec 28, 2022
Color scales in Python for humans

colorlover Color scales for humans IPython notebook: https://plot.ly/ipython-notebooks/color-scales/ import colorlover as cl from IPython.display impo

Plotly 146 Sep 25, 2022
ecoglib: visualization and statistics for high density microecog signals

ecoglib: visualization and statistics for high density microecog signals This library contains high-level analysis tools for "topos" and "chronos" asp

1 Nov 17, 2021
🐍PyNode Next allows you to easily create beautiful graph visualisations and animations

PyNode Next A complete rewrite of PyNode for the modern era. Up to five times faster than the original PyNode. PyNode Next allows you to easily create

ehne 3 Feb 12, 2022
Automatically Visualize any dataset, any size with a single line of code. Created by Ram Seshadri. Collaborators Welcome. Permission Granted upon Request.

AutoViz Automatically Visualize any dataset, any size with a single line of code. AutoViz performs automatic visualization of any dataset with one lin

AutoViz and Auto_ViML 1k Jan 02, 2023
CONTRIBUTIONS ONLY: Voluptuous, despite the name, is a Python data validation library.

CONTRIBUTIONS ONLY What does this mean? I do not have time to fix issues myself. The only way fixes or new features will be added is by people submitt

Alec Thomas 1.8k Dec 31, 2022
Using SQLite within Python to create database and analyze Starcraft 2 units data (Pandas also used)

SQLite python Starcraft 2 English This project shows the usage of SQLite with python. To create, modify and communicate with the SQLite database from

1 Dec 30, 2021
Flow-based visual scripting for Python

A simple visual node editor for Python Ryven combines flow-based visual scripting with Python. It gives you absolute freedom for your nodes and a simp

Leon Thomm 3.1k Jan 06, 2023
This component provides a wrapper to display SHAP plots in Streamlit.

streamlit-shap This component provides a wrapper to display SHAP plots in Streamlit.

Snehan Kekre 30 Dec 10, 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 triangul

Ivy 61 Dec 29, 2022
Small project demonstrating the use of Grafana and InfluxDB for monitoring the speed of an internet connection

Speedtest monitor for Grafana A small project that allows internet speed monitoring using Grafana, InfluxDB 2 and Speedtest. Demo Requirements Docker

Joshua Ghali 3 Aug 06, 2021
Use Perspective to create the chart for the trader’s dashboard

Task Overview | Installation Instructions | Link to Module 3 Introduction Experience Technology at JP Morgan Chase Try out what real work is like in t

Abdulazeez Jimoh 1 Jan 22, 2022
UNMAINTAINED! Renders beautiful SVG maps in Python.

Kartograph is not maintained anymore As you probably already guessed from the commit history in this repo, Kartograph.py is not maintained, which mean

1k Dec 09, 2022
Extract data from ThousandEyes REST API and visualize it on your customized Grafana Dashboard.

ThousandEyes Grafana Dashboard Extract data from the ThousandEyes REST API and visualize it on your customized Grafana Dashboard. Deploy Grafana, Infl

Flo Pachinger 16 Nov 26, 2022
NorthPitch is a python soccer plotting library that sits on top of Matplotlib

NorthPitch is a python soccer plotting library that sits on top of Matplotlib.

Devin Pleuler 30 Feb 22, 2022
Lightweight, extensible data validation library for Python

Cerberus Cerberus is a lightweight and extensible data validation library for Python. v = Validator({'name': {'type': 'string'}}) v.validate({

eve 2.9k Dec 27, 2022
A dashboard built using Plotly-Dash for interactive visualization of Dex-connected individuals across the country.

Dashboard For The DexConnect Platform of Dexterity Global Working prototype submission for internship at Dexterity Global Group. Dashboard for real ti

Yashasvi Misra 2 Jun 15, 2021
Tandem Mass Spectrum Prediction with Graph Transformers

MassFormer This is the original implementation of MassFormer, a graph transformer for small molecule MS/MS prediction. Check out the preprint on arxiv

Röst Lab 13 Oct 27, 2022
An adaptable Snakemake workflow which uses GATKs best practice recommendations to perform germline mutation calling starting with BAM files

Germline Mutation Calling This Snakemake workflow follows the GATK best-practice recommandations to call small germline variants. The pipeline require

12 Dec 24, 2022
A Python package for caclulations and visualizations in geological sciences.

geo_calcs A Python package for caclulations and visualizations in geological sciences. Free software: MIT license Documentation: https://geo-calcs.rea

Drew Heasman 1 Jul 12, 2022