@@ -82,13 +82,13 @@ glue("{names} studies {fields}.")
8282How can you create the character vector of column names?
8383
8484** Challenge 2**
85- How can make ` ggplot2() ` take strings as x and y variable names? (Hint: Type ` ?aes_string() ` )
85+ How can make ` ggplot2() ` take strings as x and y variable names?
8686
87- ``` {r}
87+ ``` {r, warning = F, message = F }
8888
8989airquality %>%
90- ggplot(aes_string (x = names(airquality)[1], y = names(airquality)[2])) +
91- geom_point()+
90+ ggplot(aes (x = .data[[ names(airquality)[1]]] , y = .data[[ names(airquality)[2]]])) +
91+ geom_point()+
9292 labs(title = glue("Relationship between Ozone and {names(airquality)[2]}"),
9393 y = glue("{names(airquality)[2]}"))
9494
@@ -103,7 +103,7 @@ airquality %>%
103103create_point_plot <- function(i){
104104
105105 airquality %>%
106- ggplot(aes_string (x = names(airquality)[1], y = names(airquality)[i])) +
106+ ggplot(aes (x = .data[[ names(airquality)[1]]] , y = .data[[ names(airquality)[i]]])) +
107107 geom_point() +
108108 labs(title = glue("Relationship between Ozone and {names(airquality)[i]}"),
109109 y = glue("{names(airquality)[i]}"))
@@ -114,7 +114,7 @@ create_point_plot <- function(i){
114114
115115- The final step is to put the function in ` map() ` .
116116
117- ``` {r}
117+ ``` {r, message = F, warning = F }
118118
119119map(2:ncol(airquality), create_point_plot)
120120
0 commit comments