| fp_scaled_axis | R Documentation |
This is useful when creating contour plots for the FP response surface or factors interaction plots. It allows to add secondary axes that use the scaled factor units rather than the coded units (in range -1, 1).
fp_scaled_axis(fp, fct)
fp |
The factorial plan object |
fct |
The standard name of the factor as a string (e.g. |
A ggplot2::sec_axis object
fp_name() fp_scale()
library(tidyverse)
fp <- fp_design_matrix(2, rep=3) %>%
fp_add_names(A="Temperature (°C)", B="Pressure (bar)") %>%
fp_add_scale(A=c(20,30), B=c(2, 3))
fp$Y <- ccd_experiment_yield$base
fp.lm <- lm(Y~A*B, data=fp)
# Interaction plot:
fp %>%
mutate(
pred = predict(fp.lm),
B=factor(B)
) %>%
ggplot(aes(x=A, y=pred, color=B)) +
geom_line() +
scale_x_continuous(sec.axis = fp_scaled_axis(fp, "A"))+
scale_color_discrete(labels = fp_scale(fp, "B")) +
labs(color=fp_name(fp, "B"), y="Yield")
expand.grid(
A = seq(-1, 1, length.out=100),
B = seq(-1, 1, length.out=100)
) %>% {
mutate(., Y=predict(fp.lm, newdata=.))
} %>%
ggplot(aes(x=A, y=B, z=Y)) +
geom_contour_filled() +
scale_x_continuous(sec.axis = fp_scaled_axis(fp, "A")) +
scale_y_continuous(sec.axis = fp_scaled_axis(fp, "B")) +
labs(fill="Yield")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.