| scale_centerY | R Documentation |
solution adapted from https://stackoverflow.com/questions/31782799/how-to-use-free-scales-but-keep-a-fixed-reference-point-in-ggplot
scale_centerY(bycols, fun = min, dplot, FLAGcenterLog = TRUE, ...)
bycols |
character vector of columns to summarize by. These are typically columns you facet over |
fun |
min or max |
dplot |
data.table(measurement = nominal values, bycols...). Typically, the data that went into the plot |
FLAGcenterLog |
do the centering on log scale |
... |
arguments to geom_blank |
You need to call this function twice, once with min and once with max
geom_blank
# linear scale
dx <- copy(mtcars)
dx <- data.table(dx)
dx[,`:=`(measurement = wt-mean(wt))]
ggplot(dx, aes(mpg, measurement)) +
facet_wrap( ~ cyl, scales = "free_y") +
geom_point() +
scale_centerY("cyl", min, dx, FALSE) +
scale_centerY("cyl", max, dx, FALSE)
# log scale
dx <- copy(mtcars)
dx <- data.table(dx)
dx[,`:=`(measurement = wt/mean(wt))]
ggplot(dx, aes(mpg, measurement)) +
facet_wrap( ~ cyl, scales = "free_y") +
geom_point() +
scale_centerY("cyl", min, dx, TRUE) +
scale_centerY("cyl", max, dx, TRUE) +
scale_y_log10()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.