knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(fbhelpers) library(dplyr) library(ggplot2) tibble(x = runif(1000), e =rnorm(1000, sd = 0.5), y = 1 + x + e) %>% mutate(x_cut = cut(x, seq(0,1,.05))) %>% group_by(x_cut) %>% summarise(n = n(), mean = mean(y)) %>% assign("dff",.,envir = .GlobalEnv) %>% # used to get scaling factors for the secondary axis. ggplot() + aes(x = x_cut) + geom_col(aes(y = n * max(mean) / max(n)), fill = "yellow", color = "black") + geom_line(aes(y = mean), group = 1, size = 1) + geom_point(aes(y = mean)) + scale_y_continuous( expand = c(0,0,0.1,0), sec.axis = sec_axis(trans = ~ . * max(dff$n) / max(dff$mean), )) + theme_emblem() + theme(axis.text.x = element_text(angle = 45, hjust = 1)) + xlab("x") + ylab("response") + ggtitle("random plot")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.