# to create README.md library(rmarkdown) render("README.Rmd", md_document(fig_width = 6, fig_height = 3))
ffplot
is a simple and intuitive plotting command. The goal is that you can use it without thinking or looking up
documentation.
Status: totally alpha! Download and enjoy.
library(devtools) install_github("hughjonesd/ffplot")
The basic form of every ffplot
command is:
ffplot(y_variables ~ x_variable, data)
The data is split up by unique values of x, and y variables are calculated. We'll demonstrate using the diamonds
data from ggplot2.
library(ffplot) data(diamonds, package = "ggplot2") d30 <- diamonds[1:30,] head(d30)
Here's a simple scatterplot.
ffplot(price ~ carat, diamonds)
If x and y are not numeric, we get a barplot by default. We'll see how to change this later.
ffplot(cut ~ color, diamonds)
If y is not numeric but x is, you get a density plot:
ffplot(cut ~ depth, diamonds, position = "fill")
y variables can also be functions of your data. ffplot
tries to choose an appropriate way to display results:
ffplot(range(price) ~ color, d30)
Of course x variables can be functions too:
ffplot(price ~ cut(carat, 5), diamonds)
If you want to use a different plot type, just put it on the left:
ffplot(boxplot(price) ~ cut, diamonds)
You combine plots by adding terms. Here's a smooth line:
ffplot(price + smooth(price) ~ carat, diamonds)
Here we draw means and confidence intervals. ffplot
guesses that you want error bars for the built-in ci
function:
ffplot(mean(price) + ci(price, 0.95) ~ cut, diamonds)
You can add ggplot
options to the plot:
ffplot(price ~ carat, d30, shape = 3, color = "darkgreen")
Or you can add options for each y variable. If so, you'll need to specify the geom
explicitly:
ffplot(point(price, alpha = 0.2, color = "red") + smooth(price, color = "orange", size = 2, se = TRUE) ~ carat, diamonds)
To create facets, just put them in the formula after a vertical bar:
ffplot(price ~ carat | color, diamonds)
Two-way facets:
x <- ffplot(smooth(mean(price)) ~ carat | color + cut, diamonds) suppressMessages(print(x)) # annoying warning messages...
ffplot
returns a ggplot
object, so you can add functions just as with ggplot2.
library(ggplot2) ffplot(cut ~ color, diamonds) + scale_fill_grey()
It's easy to use with dplyr
or magrittr
:
library(dplyr) diamonds %>% ffplot(cut ~ color)
If you want to see what the underlying data looks like, there's the fftable
function:
fftable(range(carat) ~ color, diamonds)
Plot proportions in a group:
ffplot(hist(cut, position = "fill") ~ color, diamonds)
Barplot with confidence intervals:
ffplot(bar(mean(price)) + ci(price, 0.99) ~ color, diamonds)
Barplot of proportions with binomial confidence intervals:
ffplot(prop(cut == "Ideal") + ci(cut == "Ideal") ~ color, diamonds)
Other ggplot2 geoms
you can use:
ffplot:::geom_names
se
function for standard errors?bubble
functionprops()
function?aes()
mapping, e.g. for geom_text
labels or setting colouraes
to be in the data set from fave
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.