Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions R/facet.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ draw_facet_window = function(
nfacets, nfacet_cols, nfacet_rows,
# axes args
axes, flip, frame.plot, oxaxis, oyaxis,
xlabs, xlim, xaxt, xaxs, xaxl,
ylabs, ylim, yaxt, yaxs, yaxl,
xlabs, xlim, xlim_user, xaxt, xaxs, xaxl,
ylabs, ylim, ylim_user, yaxt, yaxs, yaxl,
asp, log,
# other args (in approx. alphabetical + group ordering)
dots,
Expand Down Expand Up @@ -293,8 +293,8 @@ draw_facet_window = function(
# individual facet.
xfree = split(c(x, xmin, xmax), facet)[[ii]]
yfree = split(c(y, ymin, ymax), facet)[[ii]]
xlim = range(xfree, na.rm = TRUE)
ylim = range(yfree, na.rm = TRUE)
if (!xlim_user) xlim = range(xfree, na.rm = TRUE)
if (!ylim_user) ylim = range(yfree, na.rm = TRUE)
xext = extendrange(xlim, f = 0.04)
yext = extendrange(ylim, f = 0.04)
# We'll save this in a special .fusr env var (list) that we'll re-use
Expand All @@ -310,14 +310,14 @@ draw_facet_window = function(
par(usr = fusr[[ii]])
# if plot frame is true then print axes per normal...
if (type %in% c("barplot", "pointrange", "errorbar", "ribbon", "boxplot", "p", "violin") && !is.null(xlabs)) {
tinyAxis(xfree, side = xside, at = xlabs, labels = names(xlabs), type = xaxt)
tinyAxis(xfree, side = xside, at = xlabs, labels = names(xlabs), type = xaxt, labeller = xaxl)
} else {
tinyAxis(xfree, side = xside, type = xaxt)
tinyAxis(xfree, side = xside, type = xaxt, labeller = xaxl)
}
if (isTRUE(flip) && type %in% c("barplot", "pointrange", "errorbar", "ribbon", "boxplot", "p", "violin") && !is.null(ylabs)) {
tinyAxis(yfree, side = yside, at = ylabs, labels = names(ylabs), type = yaxt)
tinyAxis(yfree, side = yside, at = ylabs, labels = names(ylabs), type = yaxt, labeller = yaxl)
} else {
tinyAxis(yfree, side = yside, type = yaxt)
tinyAxis(yfree, side = yside, type = yaxt, labeller = yaxl)
}

# For fixed facets we can just reuse the same plot extent and axes limits
Expand Down
9 changes: 6 additions & 3 deletions R/lim.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
# calculate limits of each plot

lim_args = function(datapoints, xlim, ylim, type) {

if (is.null(xlim))

xlim_user = ylim_user = TRUE
if (is.null(xlim)) {
xlim = range(c(datapoints[["x"]], datapoints[["xmin"]],
datapoints[["xmax"]]), finite = TRUE)
if (is.null(ylim))
}
if (is.null(ylim)) {
ylim = range(c(datapoints[["y"]], datapoints[["ymin"]],
datapoints[["ymax"]]), finite = TRUE)
}

if (identical(type, "boxplot")) {
xlim = xlim + c(-0.5, 0.5)
Expand Down
15 changes: 9 additions & 6 deletions R/tinyplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,6 @@ tinyplot.default = function(
if (is.null(ylab)) ylab = "Density"
} else if (type == "function") {
if (is.null(ylab)) ylab = "Frequency"
# } else if (type != "histogram") {
} else if (!(type %in% c("histogram", "barplot"))) {
y = x
x = seq_along(x)
Expand All @@ -756,8 +755,12 @@ tinyplot.default = function(
}

if (is.null(xlab)) xlab = x_dep
# if (is.null(ylab)) ylab = y_dep
if (is.null(ylab) && type != "histogram") ylab = y_dep

# flag(s) indicating whether x/ylim was set by the user (needed later for
# special case where facets are free but still want to set x/ylim manually)
xlim_user = !is.null(xlim)
ylim_user = !is.null(ylim)

# alias
if (is.null(bg) && !is.null(fill)) bg = fill
Expand Down Expand Up @@ -1148,8 +1151,8 @@ tinyplot.default = function(
# axes args
axes = axes, flip = flip, frame.plot = frame.plot,
oxaxis = oxaxis, oyaxis = oyaxis,
xlabs = xlabs, xlim = xlim, xaxt = xaxt, xaxs = xaxs, xaxl = xaxl,
ylabs = ylabs, ylim = ylim, yaxt = yaxt, yaxs = yaxs, yaxl = yaxl,
xlabs = xlabs, xlim = xlim, xlim_user = xlim_user, xaxt = xaxt, xaxs = xaxs, xaxl = xaxl,
ylabs = ylabs, ylim = ylim, ylim_user = ylim_user, yaxt = yaxt, yaxs = yaxs, yaxl = yaxl,
asp = asp, log = log,
# other args (in approx. alphabetical + group ordering)
dots = dots,
Expand All @@ -1172,8 +1175,8 @@ tinyplot.default = function(
nfacets = nfacets, nfacet_cols = nfacet_cols, nfacet_rows = nfacet_rows,
axes = axes, flip = flip, frame.plot = frame.plot,
oxaxis = oxaxis, oyaxis = oyaxis,
xlabs = xlabs, xlim = xlim, xaxt = xaxt, xaxs = xaxs, xaxl = xaxl,
ylabs = ylabs, ylim = ylim, yaxt = yaxt, yaxs = yaxs, yaxl = yaxl,
xlabs = xlabs, xlim = xlim, xlim_user = xlim_user, xaxt = xaxt, xaxs = xaxs, xaxl = xaxl,
ylabs = ylabs, ylim = ylim, ylim_user = ylim_user, yaxt = yaxt, yaxs = yaxs, yaxl = yaxl,
asp = asp, log = log,
dots = dots,
draw = draw,
Expand Down
2 changes: 2 additions & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"xaxt",
"xlabs",
"xlim",
"xlim_user",
"xlvls",
"xmax",
"xmin",
Expand All @@ -68,6 +69,7 @@
"yaxt",
"ylabs",
"ylim",
"ylim_user",
"ymax",
"ymin"
))
Expand Down
2 changes: 2 additions & 0 deletions man/facet.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.