flexplot | R Documentation |
Create a flexible plot. Flexplot will allow users to create histograms, barcharts, jittered density plots, paneled plots, scatterplots, etc. Much of the decision-making is automated, which is pretty freaking awesome.
flexplot(
formula,
data = NULL,
related = F,
bins = 3,
labels = NULL,
breaks = NULL,
method = "loess",
se = NULL,
ghost.line = NULL,
ghost.reference = NULL,
spread = c("quartiles", "stdev", "sterr"),
jitter = NULL,
raw.data = T,
sample = Inf,
prediction = NULL,
suppress_smooth = F,
alpha = 0.99977,
plot.string = F,
silent = F,
third.eye = NULL,
plot.type = c("histogram", "qq", "density", "boxplot", "violin", "line"),
return_data = F,
...
)
formula |
A formula of the form y~x + a | b + z |
data |
The dataset |
related |
Are variables related? If so, it will show a plot of difference scores, rather than the raw scores (for a related t test). |
bins |
The preferred number of bins used when putting quantitative variables into categories. A list can be used if different amounts are wanted for different variables. However, sometimes flexplot cannot have that number of bins, but it will try to make it work. |
labels |
A list of the same length as bins |
breaks |
The breaks to be used for the bins. |
method |
The method to be used to draw the lines. Defaults to loess, but it could be "lm", "logistic", "polynomial", "cubic", "rlm", or "glm". Although you could always try something else. Sometimes flexplot possesses superhuman intelligence. |
se |
Should standard errors be drawn? Defaults to T. |
ghost.line |
Color of the ghost line. Default is NULL (in which case, the ghost line isn't shown). |
ghost.reference |
What groups should be referenced for the ghost line? See examples for how to specify this. |
spread |
Specifies how the "whiskers" of the plots should be draw. Can be "quartiles", "stdev", or "sterr." Defaults to quartiles |
jitter |
Can be either T/F, or a vector of length two, specifying the degree of jitter for the x and y axis, respectively. |
raw.data |
Should raw data be plotted? Defaults to yeaaaaahhhhh-buddy! (i.e., T) |
sample |
Should a sample of the data be plotted? Defaults to NOT sampling (for all variables). |
prediction |
Predicted values for a prediction line. Defaults to NULL. This is generally NOT used when just using flexplot, but it's helpful with the wrapper function compare.fits |
suppress_smooth |
Should a fitted line be repressed? Defaults to FALSE |
alpha |
The transparency of the datapoints. |
plot.string |
Should the code to generate the plot be outputted? In the background, flexplot is creating a bunch of strings before it evaluates the model. Users can export the string, in case they want to modify the ggplot object |
silent |
Should all messages be suppressed? Defaults to F. |
third.eye |
Should the "third eye" be employed? The third eye will be implemented shortly. |
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. |
return_data |
Should flexplot return the dataset? Defaults to No. This is useful if you want to recycle the bin assigments from flexplot. |
... |
Other arguments passed to |
Formula takes the form of y~x + a | b + z. Everything on the right of | will occur in panels (in this case, b will be in the columns and z will be in the rows). Any numeric variables between ~ and | will fall on the x axis and categorical predictors will be color-coded/symbol-coded/line-coded (if user specifies). If more than one numeric variable is specified after ~, the second (and third) will be binned. No more than four variables are allow (otherwise, cognitive load is too high). If the user wishes to include another variable, I recommend they create separate plots, one for each level of the new variable (or a binned level of a numeric variable).
To better enable comparisons across panels, Flexplot implements "ghost lines," which simply repeat the line from one panel to another. For more information about ghost lines, see the vignette (also available at https://psyarxiv.com/kh9c3/)
a ggplot2 object
Dustin Fife
data(exercise_data)
d = exercise_data
# # #### histograms and barcharts
flexplot(income~1, data=d)
flexplot(gender~1, data=d)
# ### scatter plot
flexplot(weight.loss~motivation, data=d)
flexplot(weight.loss~motivation, data=d, method="lm", se=FALSE)
#### with regression line and without standard error
# ### mean plots
flexplot(weight.loss~therapy.type, data=d)
flexplot(weight.loss~therapy.type, data=d, raw.data=FALSE)
## without raw data
# ### CHI SQUARE PLOT
flexplot(therapy.type~gender, data=d)
# ### INTERACTION PLOT
## Not run: flexplot(weight.loss~therapy.type + gender, data=d)
flexplot(weight.loss~therapy.type + gender, data=d, sample=50)
#### sampling 50 people instead (to make it less noisy)
# #### ANCOVA PLOT
flexplot(weight.loss~motivation + gender, data=d, se=FALSE) ### remove se
# #### 2N PLOT (2 NUMERIC VARIABLE PLOTS)
flexplot(weight.loss~motivation + income, data=d, se=FALSE, method="lm")
flexplot(weight.loss~motivation + income, data=d, se=FALSE, method="lm",
breaks = list(income = c(95000, 100000, 105000)),
labels=list(income = c("<95K", "<100K", "<105K", ">105K")))
### change labels for income
# #### 3N plot
flexplot(weight.loss~motivation + income + health, data=d, se=FALSE, method="lm")
## different lines for income
flexplot(weight.loss~motivation | income + health, data=d, se=FALSE, method="lm")
## relabel income
flexplot(weight.loss~motivation | income + health, data=d, se=FALSE, method="lm", ghost.line="red",
breaks = list(income = c(95000, 100000, 105000)),
labels=list(income = c("<95K", "<100K", "<105K", ">105K")))
flexplot(weight.loss~motivation | income + health, data=d, se=FALSE, method="lm",
ghost.line="red", ghost.reference=list("health"=31, "income"=90000))
flexplot(weight.loss~motivation | income + health, data=d, se=FALSE, method="lm",
ghost.line="red", ghost.reference=list("health"=31))
flexplot(weight.loss~motivation | income + health, data=d, se=FALSE, method="lm",
ghost.line="red", ghost.reference=list("health"=31, "income"=90000, "motivation"=10))
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.