sinhrks / ggfortify Goto Github PK
View Code? Open in Web Editor NEWDefine fortify and autoplot functions to allow ggplot2 to handle some popular R packages.
License: Other
Define fortify and autoplot functions to allow ggplot2 to handle some popular R packages.
License: Other
ggfortify gives different PCA loadings in biplot when compared with stats::biplot ouput. This is also reported here.
By default, autoplot
uses the names from survivalFit[["strata"]]
as the legend levels. They have a variableName=value
format. Programmer's variable names are not something that a figure to be published in a medical journal should have displayed. Perhaps autoplot
should use code like gsub(".*=", '', strataNames)
to place only the level name in the legend. autoplot
also lacks any legend customisation options, such as the legend title.
Utilize {broom}
as much if outputs data.frame
which has enough information for plotting.
aareg_tidiers
anova_tidiers
cch_tidiers
confint_tidy
coxph_tidiers
cv.glmnet_tidiers
felm_tidiers
gam_tidiers
glmnet_tidiers
lme4_tidiers
multcomp_tidiers
nls_tidiers
pyears_tidiers
ridgelm_tidiers
rlm_tidiers
sexpfit_tidiers
smooth.spline_tidiers
sp_tidiers
survfit_tidiers
survreg_tidiers
tidy.manova
tidy.map
tidy.TukeyHSD
autoplot
should not be affected. Column names output from fortify
may be affected.
kmeans_tidiers
tidy.density
tidy.spec
tidy.ts
: Doesn't preserve timestamps.Arima_tidiers
: Not usable for autoplot
.fortify
is already defined in {ggplot2}
. Considering to use autoplot
internally for simplification.glm
.htest_tidiers
: Plotting single test result is not very useful. Reconsider if there is good example.tidy.pairwise.htest
: Doesn't contain confidence intervals. Considering to use {pairwiseCI}tidy.ftable
: No need to use, simply call as.data.frame
.post_fortify
to always attach base_class
ggplot
instanciation to geom_factory
, do not include duplicated data to geom.The final line of fortify.survfit
, post_fortify(d)
, seems to be a no-op.
> d2 = post_fortify(d)
> identical(d, d2)
[1] TRUE
Should it just be removed? This might be the same as #102.
A while back, I wrote an autoplot method for spline basis objects: http://stats.stackexchange.com/a/179099/5736
Would you be interested in including this in ggfortify?
Looks possible but can't work well with current ggmultiplot
as legend
must be considered as plot (grob). Needs separated class to dot this, or logic to merge the same legends when output.
p <- autoplot(lm(Petal.Width ~ Petal.Length, data = iris), colour = 'Species', data = iris)
grob <- ggplotGrob(p@plots[[1]])
leg <- grob$grobs[[which(grob$layout$name == "guide-box")]]
plots <- lapply(p@plots, function(x) x + theme(legend.position = 'none'))
plots[[5]] <- leg
layout_matrix = rbind(c(1, 2, 5), c(3, 4, 5))
do.call(grid.arrange, c(plots, list(ncol = 3, layout_matrix = layout_matrix))
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')
In both install.packages
and install_github
.
Error in eval(expr, envir, enclos) : could not find function "eval"
Error : unable to load R code in package ‘ggfortify’
ERROR: lazy loading failed for package ‘ggfortify’
Maybe related to ggplto2
dev version:
Hola,
Is it possible to use lda {MASS}? Can you please provide an example?
Thanks
I have a survival grouping where the factor levels are different to alphabetical ordering.
levels(samplesGroups)
[1] "Low" "High"
survfit
keeps these in the correct order
> survivalFit
Call: survfit(formula = survivalData ~ samplesGroups)
n events median 0.95LCL 0.95UCL
samplesGroups=Low 17 11 3.63 1.838 NA
samplesGroups=High 17 10 4.55 0.992 NA
However, autoplot
always places High first and Low second in the legend, because it ignores the ordering and just rearranges everything alphabetically. This should not happen.
Received kind email from CRAN:
Presumably from an update of one of
1 changepoint 2015-11-09
2 timeSeries 2015-11-09we now see your package fail its tests with
checking tests ... ERROR
Running the tests in ‘tests/test-all.R’ failed.
Last 13 lines of output:
3: In princomp.default(df, center = TRUE, scale = FALSE) :
extra arguments 'center', 'scale' will be disregarded
4: In princomp.default(df, center = FALSE, scale = FALSE) :
extra arguments 'center', 'scale' will be disregarded
5: In princomp.default(USArrests, center = TRUE, scale = TRUE) :
extra arguments 'center', 'scale' will be disregarded
6: In princomp.default(USArrests, center = FALSE, scale = TRUE) :
extra arguments 'center', 'scale' will be disregarded
7: In princomp.default(USArrests, center = TRUE, scale = FALSE) :
extra arguments 'center', 'scale' will be disregarded
8: In princomp.default(USArrests, center = FALSE, scale = FALSE) :
extra arguments 'center', 'scale' will be disregarded
Execution halted
fortify
and autoplot
argnames to be compat with {ggplot2}
The legend is missing.
species <- as.numeric(factor(iris[, "Species"]))
autoplot(prcomp(iris[, 1:4]), colour = species, environment = environment())
Warning message:
In if (value %in% columns) { :
the condition has length > 1 and only the first element will be used
Picking a column from the data frame works without a problem.
autoplot(prcomp(iris[, 1:4]), data = iris, colour = "Species") # Legend shown.
If log
is specified for fortify.survfit
, the original values are returned unchanged.
fun <- switch(fun, log = function(x) x,
Is that a bug?
There are few plotting functions using grieExtra::grid.arrange
internally, such as autoplot.lm
. These function doesn't have return value, thus we cannot decorate it later.
Consider a better way to allow decoration.
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)
}
Hi,
Love the package.
Maybe I'm just being stupid but can I use themes like I would in typical ggplot?
I'd hope
autoplot(lm(rnorm(10)~rnorm(10, 2))) +
theme_bw()
would theme the 4 facets with the black and white theme. This syntax works for autoplot in other cases (e.g. microbenchmark).
geom_factory
in label handling (#31)For some reason when I try to plot labels I can't ever the actual labels even after renaming the rows
Modify .gitignore
to reduce package file size.
Using R v3.2.3 w/ ggfortify 0.1.0 and ggplot2 2.0.0 fails
> autoplot(survfit(Surv(time, status) ~ sex, data = lung))
Error in get(x, envir = this, inherits = inh)(this, ...) :
unused argument (TRUE)
Other conversation about this at: tidyverse/ggplot2#1458
Hi,
I get similar error message as in #137 when doing any polynomial regression.
Please see reproducible example:
library(ggfortify)
model <- lm(mpg ~ poly(hp, 2, raw = TRUE),data = mtcars)
autoplot(model)
Error: Each variable must be a 1d atomic vector or list.
Problem variables: 'poly(hp, 2, raw = TRUE)'
par(mfrow = c(2,2))
plot(model)
Remove legacy code for ggplot2 v1.0 or prior once v1.1.0 has been released. Related to #47.
See #46.
Avoid to use rownames
internally, follow dplyr
0.4- manner.
Hi
I'm trying to plot acf outputs with ggplot2, and trying to use ggfortify, but get the error below.
Best,
Richard
library(ggplot2)
library(ggfortify)
Loading required package: scales
Error in unloadNamespace(package) :
namespace ‘scales’ is imported by ‘ggplot2’ so cannot be unloaded
Error in library(pkg, character.only = TRUE, logical.return = TRUE, lib.loc = lib.loc) :
Package ‘scales’ version 0.2.4 cannot be unloaded
Using R on Ubuntu Trusty: R: 3.2.0-4trusty0
Unlike the base survival plot, it's not possible with ggfortify to set a different line colour for each patient group. Looking at the documentation of autoplot.survfit
, it's only possible to choose a single colour for the parameter surv.colour
.
As Hadley tweeted, forecast package will natively support ggplot2. That's a great news per se, but this means that they implemented their own fortify
and autoplot
methods, which conflict with ones in ggfortify package.
dplyr::intersect(ls(asNamespace('ggfortify')), ls(asNamespace('forecast')))
#> [1] "autoplot.acf" "autoplot.Arima" "autoplot.decomposed.ts" "autoplot.ets" "autoplot.forecast"
#> [6] "autoplot.stl" "autoplot.ts" "fortify.forecast" "fortify.ts"
I tried the dev version of forecast package and found the error (Sorry, I haven't dig into the detail yet... Please forgive me to just drop the console log here.):
library(ggplot2)
library(forecast)
# no problem here
ggplot(AirPassengers, aes(x, y)) + geom_forecast()
library(ggfortify)
#> Loading required package: proto
# fail!
ggplot(AirPassengers, aes(x, y)) + geom_forecast()
#> Error in eval(expr, envir, enclos) : object 'x' not found
Session info:
devtools::session_info()
#> Session info --------------------------------------------------------------------------------------------------------------------------
#> setting value
#> version R version 3.2.3 (2015-12-10)
#> system x86_64, linux-gnu
#> ui RStudio (0.99.878)
#> language (EN)
#> collate en_US.UTF-8
#> tz <NA>
#> date 2016-02-18
#>
#> Packages ------------------------------------------------------------------------------------------------------------------------------
#> package * version date source
#> assertthat 0.1 2013-12-06 CRAN (R 3.2.2)
#> colorspace 1.2-6 2015-03-11 CRAN (R 3.2.2)
#> DBI 0.3.1 2014-09-24 CRAN (R 3.2.2)
#> devtools 1.10.0 2016-01-23 CRAN (R 3.2.3)
#> digest 0.6.9 2016-01-08 CRAN (R 3.2.3)
#> dplyr 0.4.3.9000 2015-10-01 Github (hadley/dplyr@dd10ccd)
#> forecast * 7.0 2016-02-18 Github (robjhyndman/forecast@451cb34)
#> fracdiff 1.4-2 2012-12-02 CRAN (R 3.2.2)
#> ggfortify * 0.1.0 2015-11-30 CRAN (R 3.2.3)
#> ggplot2 * 2.0.0 2015-12-18 CRAN (R 3.2.2)
#> gridExtra 2.0.0 2015-07-14 CRAN (R 3.2.2)
#> gtable 0.1.2 2012-12-05 CRAN (R 3.0.0)
#> labeling 0.3 2014-08-23 CRAN (R 3.2.2)
#> lattice 0.20-33 2015-07-14 CRAN (R 3.2.1)
#> magrittr 1.5 2014-11-22 CRAN (R 3.2.2)
#> memoise 1.0.0 2016-01-29 CRAN (R 3.2.3)
#> munsell 0.4.3 2016-02-13 CRAN (R 3.2.3)
#> nnet 7.3-12 2016-02-02 CRAN (R 3.2.3)
#> plyr 1.8.3 2015-06-12 CRAN (R 3.2.2)
#> proto * 0.3-10 2012-12-22 CRAN (R 3.0.0)
#> quadprog 1.5-5 2013-04-17 CRAN (R 3.2.2)
#> R6 2.1.2 2016-01-26 CRAN (R 3.2.3)
#> Rcpp 0.12.3 2016-01-10 CRAN (R 3.2.3)
#> scales 0.3.0.9000 2015-09-21 Github (hadley/scales@7fc502c)
#> tidyr 0.4.1 2016-02-05 CRAN (R 3.2.3)
#> timeDate * 3012.100 2015-01-23 CRAN (R 3.2.2)
#> tseries 0.10-34 2015-02-20 CRAN (R 3.2.2)
#> zoo * 1.7-12 2015-03-16 CRAN (R 3.2.2)
binomial glm() models are often fit with a two column response variable. autoplot for these models is failing. Here is a reproducible example.
library(ggfortify)
data(menarche)
glm.out <- glm(cbind(Menarche, Total-Menarche) ~ Age, family=binomial(logit), data=menarche)
autoplot(glm.out) # fails
#Error: Each variable must be a 1d atomic vector or list.
#Problem variables: 'cbind(Menarche, Total - Menarche)'
# works fine
par(mfrow = c(2,2))
plot(glm.out)
There are some classes which doesn't hold original data itself, but stores a call signature when the model was created. If autoplot
can retrieve original data from parent environment, we can omit the explicit data
keyword.
Some standard function behave like above, but it can be an unexpected result if the original variable has been changed. Thus this behavior should be explicitly turned on by global option (or argument).
I'm trying to use autoplot on glm and lm objects. I am getting errors about dplyr exported objects.
> autoplot(lm(c(1:10)~ rnorm(10)))
Error: 'arrange_' is not an exported object from 'namespace:dplyr'
I tried to reinstall ggfortify from github and got
Error: processing vignette 'basics.Rmd' failed with diagnostics:
'select_' is not an exported object from 'namespace:dplyr'
Has something changed in dplyr that means these functions are broken? Thanks in advance for any help.
My sessionInfo is
R version 3.1.1 (2014-07-10)
Platform: x86_64-pc-linux-gnu (64-bit)
locale:
[1] LC_CTYPE=en_GB.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_GB.UTF-8 LC_COLLATE=en_GB.UTF-8
[5] LC_MONETARY=en_GB.UTF-8 LC_MESSAGES=en_GB.UTF-8
[7] LC_PAPER=en_GB.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] tcltk stats graphics grDevices utils datasets methods
[8] base
other attached packages:
[1] ggfortify_0.0.1 dplyr_0.2 sqldf_0.4-10 RSQLite_1.0.0
[5] DBI_0.3.1 gsubfn_0.6-6 proto_0.3-10 readxl_0.1.0
[9] ggplot2_1.0.0
Hi,
Is it possible to add the PC1 and PC2 scores to the axes labels (like in ggbioplot: https://github.com/vqv/ggbiplot)?
Thanks
VignetteIndexEntry
Hello, thank you for the package. I find it really usefull. However, I would like the option to plot other axes instead of just the first two. Looking at the code I see that this is hardcoded. I could make a PR change that as an option if that's ok.
Should have the same interface with stats:::biplot.default
.
Then refactor autoplot.pca_common
.
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
Many packages have a NEWS or README file with links on their CRAN webpage. ggfortify
uses an unusual file format for these, so these files are not visible to the end user. Also, the NEWS file is missing information about what's new in the 0.3 version.
Hey,
Thanks for building this awesome package that helps working with ggplot2
in all circumstances ;)
There are quite a number of methods for sp
objects in ggfortify
but none for raster
objects.
The rasterVis
package include a fortify()
-like function in its function gplot()
.
I was thinking of implementing something similar in ggfortify
.
Maybe good to add a plotting parameter that allows you to turn off points to just show labels in factor plots if there isn't already a way to do this.
From yesterday, following error occurs on Travis CI repeatedly. Maybe any dependencies has been changed? Strangely I can't reproduce the issue on my local.
The branch is unmodified fork of current master:
* creating vignettes ... ERROR
Loading required package: proto
Loading required package: ggplot2
Warning in rgl.init(initValue, onlyNULL) :
RGL: unable to open X11 display
Warning in fun(libname, pkgname) : Error in 'rgl_init'
Don't know how to automatically pick scale for object of type complex. Defaulting to continuous
Don't know how to automatically pick scale for object of type complex. Defaulting to continuous
Quitting from lines 112-121 (plot_pca.Rmd)
Error: processing vignette 'plot_pca.Rmd' failed with diagnostics:
Discrete value supplied to continuous scale
Execution halted
The error message says it is related to lfda
block.
library(lfda)
# Local Fisher Discriminant Analysis (LFDA)
model <- lfda(iris[-5], iris[, 5], 4, metric="plain")
autoplot(model, data = iris, frame = TRUE, frame.colour = 'Species')
# Kernel Local Fisher Discriminant Analysis (KLFDA)
model <- klfda(kmatrixGauss(iris[-5]), iris[, 5], 4, metric="plain")
autoplot(model, data = iris, frame = TRUE, frame.colour = 'Species')
Decide how to handle ggrepel unique kwds.
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
for example:
d <- rnorm(100)
i <- c(rep("A",50),rep("B",50))
fit <- kmeans(d,2,nstart=1000)
mds <- cmdscale(dist(d))
ggplot(as.data.frame(mds)) + geom_point(aes(mds[,1],mds[,2],shape=i),size=3)
So, I don't know how to use "i" by autoplot for different point...shape in autoplot is a logical value.
Hello,
First and foremost, I would like to thank you and congratulate you on the effort you have put into this project. I was playing with the gglagplot function, when i noticed that it doesn't take a parameters to label the axis (y-axis - now get a "Data" label).
I was wondering if you can edit the list parameters, to accept ... (ellipsis), so that the parameters can be passed to ggplot function.
Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.