# NOT RUN {
mtcars2 <- df_stats( wt ~ cyl, data = mtcars)
gf_point(wt ~ hp, size = ~wt, color = ~cyl, data = mtcars) %>%
gf_abline(slope = 0, intercept = ~median, color = ~cyl, data = mtcars2)
gf_point(wt ~ hp, size = ~wt, color = ~cyl, data = mtcars) %>%
gf_hline(slope = 0, yintercept = ~median, color = ~cyl, data = mtcars2)
gf_point(mpg ~ hp, color = ~cyl, size = ~wt, data = mtcars) %>%
gf_abline(color="red", slope = -0.10, intercept = 35)
gf_point(mpg ~ hp, color = ~cyl, size = ~wt, data = mtcars) %>%
gf_abline(color = "red", slope = ~slope, intercept = ~intercept,
data = data.frame(slope = -0.10, intercept = 33:35))
gf_point(mpg ~ hp, color = ~cyl, size = ~wt, data = mtcars) %>%
gf_abline(intercept = ~ c(10, 20, 30), slope = ~c(1, 0, -1)/100,
color = c("red", "green", "blue"))
# We can set the color of the guidelines while mapping color in other
# layers
gf_point(mpg ~ hp, color = ~cyl, size = ~wt, data = mtcars) %>%
gf_hline(color = "navy", yintercept = ~c(20, 25)) %>%
gf_vline(color = "brown", xintercept = ~c(200, 300))
# If we want to map the color of the guidelines, it must work with the
# scale of the other colors in the plot.
gf_point(mpg ~ hp, size = ~wt, data = mtcars, alpha = 0.3) %>%
gf_hline(color = ~"horizontal", yintercept = ~c(20, 25)) %>%
gf_vline(color = ~"vertical", xintercept = ~c(100, 200, 300), data = NA)
gf_point(mpg ~ hp, size = ~wt, color = ~ factor(cyl), data = mtcars, alpha = 0.3) %>%
gf_hline(color = "orange", yintercept = 20, data = NA) %>%
gf_vline(color = ~c("4", "6", "8"), xintercept = c(80, 120, 250), data = NA) %>%
# reversing the layers requires using inherit = FALSE
gf_hline(color = "orange", yintercept = 20, data = NA) %>%
gf_vline(color = ~c("4", "6", "8"), xintercept = c(80, 120, 250), data = NA) %>%
gf_point(mpg ~ hp, size = ~wt, color = ~ factor(cyl), data = mtcars, alpha = 0.3,
inherit = FALSE)
# }
Run the code above in your browser using DataLab