@@ -82,13 +82,13 @@ glue("{names} studies {fields}.")
82
82
How can you create the character vector of column names?
83
83
84
84
** 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?
86
86
87
- ``` {r}
87
+ ``` {r, warning = F, message = F }
88
88
89
89
airquality %>%
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()+
92
92
labs(title = glue("Relationship between Ozone and {names(airquality)[2]}"),
93
93
y = glue("{names(airquality)[2]}"))
94
94
@@ -103,7 +103,7 @@ airquality %>%
103
103
create_point_plot <- function(i){
104
104
105
105
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]]])) +
107
107
geom_point() +
108
108
labs(title = glue("Relationship between Ozone and {names(airquality)[i]}"),
109
109
y = glue("{names(airquality)[i]}"))
@@ -114,7 +114,7 @@ create_point_plot <- function(i){
114
114
115
115
- The final step is to put the function in ` map() ` .
116
116
117
- ``` {r}
117
+ ``` {r, message = F, warning = F }
118
118
119
119
map(2:ncol(airquality), create_point_plot)
120
120
0 commit comments