Skip to content

Commit

Permalink
Merge pull request #48 from dustinfife/development
Browse files Browse the repository at this point in the history
Merge dev into master post plot.types
  • Loading branch information
dustinfife authored Feb 26, 2020
2 parents 14f4d2f + 02a85a9 commit 9e5af35
Show file tree
Hide file tree
Showing 126 changed files with 29,750 additions and 19,108 deletions.
Binary file modified .DS_Store
Binary file not shown.
13 changes: 7 additions & 6 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ README_files/
tests/
^doc$
^Meta$
jasp_documentation/
paranormal.csv
EJ notes.rtf
R/flexplota.b.R
# stuff to ignore jasp when doing CMD check
R/glinmod_jasp.R
R/linmod_jasp.R
R/flexplot_jasp2.R
R/mixedmod_jasp.R
R/jasp_common.R

# R/glinmod_jasp.R
# R/linmod_jasp.R
# R/flexplot_jasp2.R
# R/mixedmod_jasp.R
# R/jasp_common.R
R/flexplota.h.R
R/glmbasic.b.R
R/glmbasic.h.R
Expand Down
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: flexplot
Type: Package
Title: Graphically Based Data Analysis Using Flexplot
Version: 0.7.2
Version: 0.7.4
Author: Dustin Fife
Maintainer: Dustin Fife <fife.dustin@gmail.com>
Description: The ‘flexplot’ suite is a graphically-based set of tools for doing data analysis. flexplot() allows users to specify a formula and the software automatically chooses what sort of graphic to present. Analysis can be paired with visuals using the visualize() function, such that the software will choose an appropriate graphic to match an R model object.
Expand All @@ -10,7 +10,6 @@ Encoding: UTF-8
LazyData: true
Depends: stats
Imports: cowplot,
ggplot2,
MASS,
tibble,
withr,
Expand All @@ -19,7 +18,8 @@ Imports: cowplot,
forcats,
purrr,
plyr,
R6
R6,
ggplot2
Suggests: jmvcore (>= 0.8.5),
vdiffr,
knitr,
Expand Down
6 changes: 5 additions & 1 deletion R/compare.fits.R
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,11 @@ compare.fits = function(formula, data, model1, model2=NULL, return.preds=F, repo
if (return.preds){
prediction.model
} else {

### for logistic, add one to the predictions
if (model1.type == "glm") {
if (family(model1)$link=="logit" & !is.numeric(data[,outcome[1]])){
prediction.model$prediction = prediction.model$prediction + 1
}}
flexplot(formula, data=data, prediction=prediction.model, suppress_smooth=T, se=F, ...)
}

Expand Down
18 changes: 18 additions & 0 deletions R/data_documentation.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
#' Simulated Dataset About Experiences with the Paranormal
#'
#' A dataset containing combat attributes of almost 812 fighters in the final
#' Avengers battle. This dataset illustrates several types of problems one might
#' encounter for univariate variables, including bimodality, zero-inflated data,
#' outliers, mixed up labels, etc.
#'
#' @format A data frame with 1000 rows and 7 variables: \describe{
#' \item{conviction}{Degree of conviction they have about the existence of the
#' paranormal} \item{fear}{How much they fear being kidnapped by aliens}
#' \item{time}{How much time they spend a year researching the paranormal}
#' \item{kidnapped}{Whether they've been kidnapped by aliens}
#' \item{experiences.type}{What type of experiences they have had with the
#' paranormal? Can be "eerie feeling," "presence watching", "saw UFO", "saw ghost", or "heard voice"}
#' \item{income}{How much money they make}
#' \item{age}{Age of respondent}}
"paranormal"

#' Simulated Statistics on the Final Avengers Battle
#'
#' A dataset containing combat attributes of almost 812
Expand Down
2 changes: 1 addition & 1 deletion R/estimates.R
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ estimates.lm = function(object, mc=TRUE){
)
}
### this requires superassignment to work with JASP
#dataset<<-object$model
dataset<<-object$model
all.terms = attr(terms(object), "term.labels")
mc = t(sapply(1:length(all.terms), removed.one.at.a.time, terms=all.terms, object=object))
mc = data.frame(cbind(all.terms,mc), stringsAsFactors = FALSE)
Expand Down
28 changes: 20 additions & 8 deletions R/flexplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
##' Users can export the string, in case they want to modify the ggplot object
##' @param silent Should all messages be suppressed? Defaults to F.
##' @param third.eye Should the "third eye" be employed? The third eye will be implemented shortly.
##' @param plot.type This argument allows the user to control the type of plot used. Flexplot defaults to histograms (for univariate variables)
##' but could also do qqplots (using "qq" as the argument) or density plots (using "density"). Also, the user can specify "boxplot" for boxplots and
##' "violin" for violin plots.
##' @author Dustin Fife
##' @import tibble ggplot2 R6
##' @export
Expand Down Expand Up @@ -91,7 +94,8 @@ flexplot = function(formula, data=NULL, related=F,
spread=c('quartiles', 'stdev', 'sterr'), jitter=NULL, raw.data=T,
sample=Inf,
prediction = NULL, suppress_smooth=F, alpha=.99977, plot.string=F, silent=F,
third.eye=NULL){
third.eye=NULL,
plot.type = c("histogram")){

#data = exercise_data
##### use the following to debug flexplot
Expand All @@ -102,10 +106,11 @@ flexplot = function(formula, data=NULL, related=F,
#formula = formula(weight.loss~rewards+gender|income+motivation); data=d;
#ghost.reference = list(income=90000)


spread = match.arg(spread, c('quartiles', 'stdev', 'sterr'))

### prepare the variables

### prepare the variables

varprep = flexplot_prep_variables(formula, data,
breaks = breaks, labels=labels, bins=bins,
related=related,
Expand All @@ -124,6 +129,12 @@ flexplot = function(formula, data=NULL, related=F,
##### make models into a factor if they supply predictions
if (!is.null(prediction)){
prediction$model = factor(prediction$model)

### make the levels consistent between prediction/data for axis 1
if (!is.numeric(data[[varprep$axis[1]]])){
prediction[[varprep$axis[1]]] = factor(prediction[[varprep$axis[1]]], levels=levels(data[[varprep$axis[1]]]))
}

varprep$prediction = prediction
}

Expand All @@ -150,19 +161,20 @@ flexplot = function(formula, data=NULL, related=F,
### PLOT UNIVARIATE PLOTS
bivariate = with(varprep, flexplot_bivariate_plot(formula = NULL, data=data, prediction = prediction, outcome=outcome, predictors=predictors, axis=axis,
related=related, alpha=alpha, jitter=jitter, suppress_smooth=suppress_smooth,
method=method, spread=spread))
method=method, spread=spread, plot.type=plot.type))
p = bivariate$p
points = bivariate$points
fitted = bivariate$fitted

#### all the above should take care of ALL possible plots, but now we add paneling
# browser()
facets = flexplot_panel_variables(varprep,
related=related, labels=labels, bins=bins,
suppress_smooth=suppress_smooth, method=method,
spread=spread, prediction=prediction)

if (!is.null(ghost.line) & !is.na(varprep$given[1])){ # with help from https://stackoverflow.com/questions/52682789/how-to-add-a-lowess-or-lm-line-to-an-existing-facet-grid/52683068#52683068

### bin the ghost reference if it's not null
ghost.reference = with(varprep, create_ghost_reference(ghost.reference=ghost.reference, data=data,
bins=bins, breaks=breaks, given=given, axis=axis, labels=labels))
Expand All @@ -184,7 +196,7 @@ flexplot = function(formula, data=NULL, related=F,
} else {
ghost = "xxxx"
}

### add prediction lines
if (!is.null(prediction)){
### see how many models are being compared
Expand Down Expand Up @@ -216,7 +228,7 @@ flexplot = function(formula, data=NULL, related=F,
#### change the y axis labels
theme = paste0(theme, " + scale_y_continuous(breaks = c(0,1), labels=factor.to.logistic(data,outcome, labels=T))")
}

### put objects in this environment
axis = varprep$axis; outcome = varprep$outcome; predictors = varprep$predictors; levels = length(unique(data[,outcome]))

Expand Down
Loading

0 comments on commit 9e5af35

Please sign in to comment.