|
1 | 1 | --- |
2 | 2 | title: "Star Wars Character Data" |
3 | 3 | author: "Angela Zoss" |
4 | | -date: "1/30/2020" |
| 4 | +date: "3/23/2021" |
5 | 5 | output: html_document |
6 | 6 | --- |
7 | 7 |
|
@@ -60,34 +60,33 @@ ggplot(starwars_chars, aes(height,mass)) + |
60 | 60 |
|
61 | 61 | ``` |
62 | 62 |
|
63 | | -## Add a linear trend line |
| 63 | +## Data inheritance: Add a label to (only) the heaviest character |
64 | 64 |
|
65 | 65 | ```{r} |
66 | 66 |
|
67 | | -# hint: look at the options for geom_smooth |
| 67 | +# hint: you can use "data=" in a geom layer to use different data for that layer |
68 | 68 |
|
69 | 69 | ggplot(starwars_chars, aes(height,mass)) + |
70 | 70 | geom_point() + |
71 | | - geom_smooth(method = "lm", se=FALSE) |
| 71 | + geom_text(data=starwars_chars %>% dplyr::filter(mass > 1000), aes(label=name), nudge_y = -50) |
72 | 72 |
|
73 | | -``` |
| 73 | +ggplot(starwars_chars, aes(height,mass)) + |
| 74 | + geom_point() + |
| 75 | + geom_text(data=starwars_chars %>% dplyr::filter(mass == max(mass, na.rm=T)), aes(label=name), nudge_y = -50) |
74 | 76 |
|
| 77 | +``` |
75 | 78 |
|
76 | | -## Data inheritance: Add a label to (only) the heaviest character |
| 79 | +## Advanced: Add a linear trend line |
77 | 80 |
|
78 | 81 | ```{r} |
79 | 82 |
|
80 | | -# hint: you can use "data=" in a geom layer to use different data for that layer |
81 | | -
|
82 | | -ggplot(starwars_chars, aes(height,mass)) + |
83 | | - geom_point() + |
84 | | - geom_smooth(method = "lm", se=FALSE) + |
85 | | - geom_text(data=starwars_chars %>% dplyr::filter(mass > 1000), aes(label=name), nudge_y = -50) |
| 83 | +# hint: look at the options for geom_smooth |
86 | 84 |
|
87 | 85 | ggplot(starwars_chars, aes(height,mass)) + |
88 | 86 | geom_point() + |
89 | | - geom_smooth(method = "lm", se=FALSE) + |
90 | | - geom_text(data=starwars_chars %>% dplyr::filter(mass == max(mass, na.rm=T)), aes(label=name), nudge_y = -50) |
| 87 | + geom_smooth(method = "lm", se=FALSE) |
91 | 88 |
|
92 | 89 | ``` |
93 | 90 |
|
| 91 | + |
| 92 | + |
0 commit comments