Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ca2ce27

Browse files
committed
solutions 3
1 parent f3f6b28 commit ca2ce27

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

‎solutions/03_solutions.md‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Automate Plotting
2+
3+
## Challenge 1
4+
5+
How can you create the character vector of column names?
6+
7+
**Answer** In the context of this challenge
8+
9+
```{r}
10+
11+
names(airquality)
12+
13+
```
14+
15+
## Challenge 2
16+
17+
How can make `ggplot2()` take strings as x and y variable names? (Hint: Type `?aes_string()`)
18+
19+
**Answer**
20+
21+
```{r}
22+
ggplot(aes_string(x = names(airquality)[1], y = names(airquality)[2]))
23+
```
24+
25+
This is soft deprecated, so the modern way going forward is:
26+
27+
```{r}
28+
ggplot(airquality)+
29+
geom_point(aes(x = .data[[names(airquality)[1]]],
30+
y = .data[[names(airquality)[2]]]))+
31+
... # other arguments
32+
```
33+
34+
The underlying logic works in the same way. We pass in strings to the aes() function.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /