aq = transform(
airquality,
Month = factor(month.abb[Month], levels = month.abb[5:9]),
Month2 = factor(month.name[Month], levels = month.name[5:9]),
Late = ifelse(Day > 15, "Late", "Early")
)
# default ridge plot (using the "ridge" convenience string)
tinyplot(Month ~ Temp, data = aq, type = "ridge")
# for ridge plots, we recommend pairing with the dedicated theme(s), which
# facilitate nicer y-axis labels, grid lines, etc.
tinytheme("ridge")
tinyplot(Month ~ Temp, data = aq, type = "ridge")
tinytheme("ridge2") # removes the plot frame (but keeps x-axis line)
tinyplot(Month ~ Temp, data = aq, type = "ridge")
# the "ridge(2)" themes are especially helpful for long y labels, due to
# dyanmic plot adjustment
tinyplot(Month2 ~ Temp, data = aq, type = "ridge")
# pass customization arguments through type_ridge()... for example, use
# the scale argument to change/avoid overlap of densities (more on scaling
# further below)
tinyplot(Month ~ Temp, data = aq, type = type_ridge(scale = 1))
## by grouping is also supported. two special cases of interest:
# 1) by == y (color by y groups)
tinyplot(Month ~ Temp | Month, data = aq, type = "ridge")
# 2) by == x (gradient coloring along x)
tinyplot(Month ~ Temp | Temp, data = aq, type = "ridge")
# aside: pass explicit `type_ridge(col = )` arg to set a different
# border color
tinyplot(Month ~ Temp | Temp, data = aq, type = type_ridge(col = "white"))
# gradient coloring along the x-axis can also be invoked manually without
# a legend (the next two tinyplot calls are equivalent)
# tinyplot(Month ~ Temp, data = aq, type = type_ridge(gradient = "agsunset"))
tinyplot(Month ~ Temp, data = aq, type = type_ridge(gradient = TRUE))
# aside: when combining gradient fill with alpha transparency, it may be
# better to use the raster-based approach (test on your graphics device)
tinyplot(Month ~ Temp, data = aq,
type = type_ridge(gradient = TRUE, alpha = 0.5),
main = "polygon fill (default)")
tinyplot(Month ~ Temp, data = aq,
type = type_ridge(gradient = TRUE, alpha = 0.5, raster = TRUE),
main = "raster fill")
# highlighting only the center 50% of the density (i.e., 25%-75% quantiles)
tinyplot(Month ~ Temp, data = aq, type = type_ridge(
gradient = hcl.colors(3, "Dark Mint")[c(2, 1, 2)],
probs = c(0.25, 0.75), col = "white"))
# highlighting the probability distribution by color gradient
# (darkest point = median)
tinyplot(Month ~ Temp, data = aq, type = type_ridge(
gradient = hcl.colors(250, "Dark Mint")[c(250:1, 1:250)],
probs = 0:500/500))
# faceting also works, although we recommend switching (back) to the "ridge"
# theme for faceted ridge plots
tinytheme("ridge")
tinyplot(Month ~ Ozone, facet = ~ Late, data = aq,
type = type_ridge(gradient = TRUE))
## use the joint.max argument to vary the maximum density used for
## determining relative scaling...
# jointly across all densities (default) vs. per facet
tinyplot(Month ~ Temp, facet = ~ Late, data = aq,
type = type_ridge(scale = 1))
tinyplot(Month ~ Temp, facet = ~ Late, data = aq,
type = type_ridge(scale = 1, joint.max = "facet"))
# jointly across all densities (default) vs. per by row
tinyplot(Month ~ Temp | Late, data = aq,
type = type_ridge(scale = 1))
tinyplot(Month ~ Temp | Late, data = aq,
type = type_ridge(scale = 1, joint.max = "by"))
# restore the default theme
tinytheme()
Run the code above in your browser using DataLab