Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(ggplot2)
- library(dplyr)
- # hwy : highway miles per gallon
- # 1mile == 1.60934km
- # 1gallon == 3.78541L
- # ∴ mile / gallon = 1.60934 / 3.78541 km / L
- mpg2kpl <- function(x) x * 1.60934 / 3.78541
- mpg %>%
- ggplot(aes(displ, hwy)) +
- geom_point() +
- scale_y_continuous(sec.axis = sec_axis(~ mpg2kpl(.), name = "km/L")) +
- labs(y = "mile/gal") +
- theme_classic()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement