basedjoy: (Partial) Reimplementation of the ggjoy package in base R...

Description Usage Arguments Examples

Description

ggjoy for those who are allergic to ggplot. Original ggjoy by Claus Wilke. Mistakes my own.

Usage

1
2
3
4
5
basedjoy(density.var, grouping.var, dataset, shrinkfactor = NA,
  xstretch = 3, fill.col = "grey", add.grid = TRUE, x.gridcolor = NA,
  y.gridcolor = "lightgrey", xlabtext = "", ylabtext = "",
  addgroupnames = TRUE, xlabadjLR = -1.5, global.lwd = 1.5,
  boxtype = "n", title = "", verbose = FALSE, ...)

Arguments

density.var

The variable you want to calculate densities for

grouping.var

A grouping variable (Note: doesn't work with continuous variable yet)

dataset

The input dataset, currently must be a dataframe

shrinkfactor

Controls Y overlap/distance between the distributions. Main tuning parameter for the plot. This is essentially the perspective. At 0, you are looking straight down at the distributions and will see nothing. At infinite, all density plots sit same Y axis.

xstretch

x limits controlled by min/max +/- (xstretch * kernel bandwidth). 3 is default in ggjoy.

fill.col

Fill color for the distributions; either one color or a vector of multiple, in which case a gradient will be built of length unique(grouping.var)

add.grid

Should we continue the x lines past calculated density

xlabtext

Self explanatory

ylabtext

Self explanatory

addgroupnames

Add names of the grouping variable to Y axis?

xlabadjLR

Float; adjust the group names left or right (if addgroupnames is TRUE)

global.lwd

line width of the density plot and gridlines (if applicable)

boxtype

Box drawn around plot, options in c("o","7","l","c","u") for lines or "n" for no lines (default)

title

Set "main=title"

verbose

Logical; print the kernel bandwidth?

...

Additional graphical parameters to pass to par()

gridcolor

Color of gridlines, only if add.grid is TRUE

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# Using the iris dataset:
basedjoy(density.var="Sepal.Length", grouping.var="Species", data=iris,
shrinkfactor=10, boxtype="o", mai=c(1,1,1,1))

# Using an example dataset from ggjoy
library(ggjoy)
lincoln_df <- as.data.frame(lincoln_weather)
lincoln_df$mean.temp <- as.double(lincoln_df$`Mean Temperature [F]`)
lincoln_df$mnth <- as.factor(lincoln_df$Month)

basedjoy("mean.temp", "mnth", lincoln_df, shrinkfactor=50,
      title="Monthly Temperature in Lincoln", mai=c(0.5,1.25,1,0.5),
            fill.col=c("red","blue") # very easy to establish a gradient
            )


# Explore how different values of shrinkfactor change perspective
par(mfrow=c(2,2))
for(i in 2:5){
   sf <- (i)^3
   basedjoy("mean.temp", "mnth", lincoln_df, shrinkfactor=sf, xstretch=3,
            title=paste("shrinkfactor =", sf),
            mai=c(0.75,0.75,0.5,0.1), xlabtext="Degrees Fahrenheit", ylabtext="Month",
            xlabadjLR=-1.5)
            }

kippjohnson/kippr documentation built on May 12, 2019, 2:02 p.m.