From R for Data Science
Exercises 3.5
I’m good enough, I’m smart enough, and doggone it, people like me. ~ the disgraced Al Franken
1-Why does this code not work?
my_variable <- 10
my_varıable
#> Error in eval(expr, envir, enclos): object 'my_varıable' not found
The “i” in my_variable is not written correctly when called on the second line.
2-Tweak each of the following R commands so that they run correctly:
libary(todyverse)
ggplot(dTA = mpg) +
geom_point(maping = aes(x = displ y = hwy)) +
geom_smooth(method = "lm)
Correction:
library(tidyverse)
> ggplot(data = mpg) +
+ geom_point(mapping = aes(x = displ, y = hwy)) +
+ geom_smooth(aes(x=displ, y=hwy), method="lm")
3-Press Option + Shift + K / Alt + Shift + K. What happens? How can you get to the same place using the menus?
Keyboard Shortcut Quick Reference comes up.
You can use Tools -> Keyboard Shortcuts Help
4-Let’s revisit an exercise from the Section 2.6. Run the following lines of code. Which of the two plots is saved as mpg-plot.png? Why?
my_bar_plot <- ggplot(mpg, aes(x = class)) +
geom_bar()
my_scatter_plot <- ggplot(mpg, aes(x = cty, y = hwy)) +
geom_point()
ggsave(filename = "mpg-plot.png", plot = my_bar_plot)
The my_bar_plot plot is saved because on ggsave, plot=my_bar_plot