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 napari plugin for visualising and interacting with electron cryotomograms.

napari-tomoslice A napari plugin for visualising and interacting with electron cryotomograms. Installation You can install napari-tomoslice via pip: p

3 Jan 03, 2023
A Python function that makes flower plots.

Flower plot A Python 3.9+ function that makes flower plots. Installation This package requires at least Python 3.9. pip install

Thomas Roder 4 Jun 12, 2022
Glue is a python project to link visualizations of scientific datasets across many files.

Glue Glue is a python project to link visualizations of scientific datasets across many files. Click on the image for a quick demo: Features Interacti

675 Dec 09, 2022
Cartopy - a cartographic python library with matplotlib support

Cartopy is a Python package designed to make drawing maps for data analysis and visualisation easy. Table of contents Overview Get in touch License an

1.2k Jan 01, 2023
GitHub Stats Visualizations : Transparent

GitHub Stats Visualizations : Transparent Generate visualizations of GitHub user and repository statistics using GitHub Actions. ⚠️ Disclaimer The pro

YuanYap 7 Apr 05, 2022
Implement the Perspective open source code in preparation for data visualization

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

Abdulazeez Jimoh 1 Jan 23, 2022
Generate "Jupiter" plots for circular genomes

jupiter Generate "Jupiter" plots for circular genomes Description Python scripts to generate plots from ViennaRNA output. Written in "pidgin" python w

Robert Edgar 2 Nov 29, 2021
Typical: Fast, simple, & correct data-validation using Python 3 typing.

typical: Python's Typing Toolkit Introduction Typical is a library devoted to runtime analysis, inference, validation, and enforcement of Python types

Sean 171 Jan 02, 2023
By default, networkx has problems with drawing self-loops in graphs.

By default, networkx has problems with drawing self-loops in graphs. It makes it hard to draw a graph with self-loops or to make a nicely looking chord diagram. This repository provides some code to

Vladimir Shitov 5 Jan 06, 2022
Turn a STAC catalog into a dask-based xarray

StackSTAC Turn a list of STAC items into a 4D xarray DataArray (dims: time, band, y, x), including reprojection to a common grid. The array is a lazy

Gabe Joseph 148 Dec 19, 2022
Smarthome Dashboard with Grafana & InfluxDB

Smarthome Dashboard with Grafana & InfluxDB This is a complete overhaul of my Raspberry Dashboard done with Flask. I switched from sqlite to InfluxDB

6 Oct 20, 2022
With Holoviews, your data visualizes itself.

HoloViews Stop plotting your data - annotate your data and let it visualize itself. HoloViews is an open-source Python library designed to make data a

HoloViz 2.3k Jan 02, 2023
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
CompleX Group Interactions (XGI) provides an ecosystem for the analysis and representation of complex systems with group interactions.

XGI CompleX Group Interactions (XGI) is a Python package for the representation, manipulation, and study of the structure, dynamics, and functions of

Complex Group Interactions 67 Dec 28, 2022
JSNAPY example: Validate NAT policies

JSNAPY example: Validate NAT policies Overview This example will show how to use JSNAPy to make sure the expected NAT policy matches are taking place.

Calvin Remsburg 1 Jan 07, 2022
Plotting library for IPython/Jupyter notebooks

bqplot 2-D plotting library for Project Jupyter Introduction bqplot is a 2-D visualization system for Jupyter, based on the constructs of the Grammar

3.4k Dec 30, 2022
flask extension for integration with the awesome pydantic package

Flask-Pydantic Flask extension for integration of the awesome pydantic package with Flask. Installation python3 -m pip install Flask-Pydantic Basics v

249 Jan 06, 2023
Generate a 3D Skyline in STL format and a OpenSCAD file from Gitlab contributions

Your Gitlab's contributions in a 3D Skyline gitlab-skyline is a Python command to generate a skyline figure from Gitlab contributions as Github did at

Félix Gómez 70 Dec 22, 2022
Log visualizer for whirl-framework

Lumberjack Log visualizer for whirl-framework Установка pip install -r requirements.txt Как пользоваться python3 lumberjack.py -l путь до лога -o

Vladimir Malinovskii 2 Dec 19, 2022
基于python爬虫爬取COVID-19爆发开始至今全球疫情数据并利用Echarts对数据进行分析与多样化展示。

COVID-19-Epidemic-Map 基于python爬虫爬取COVID-19爆发开始至今全球疫情数据并利用Echarts对数据进行分析与多样化展示。 觉得项目还不错的话欢迎给一个star! 项目的源码可以正常运行,各个库的版本、数据库的建表语句、运行过程中遇到的坑以及解决方式在笔记.md中都

31 Dec 15, 2022