Movatterモバイル変換


[0]ホーム

URL:


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

Commit63effbc

Browse files
committed
Fixing the link to twitter and adding some spaces
1 parente125fa4 commit63effbc

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

‎content/post/2019-08-28-you-can-replicate-almost-any-plot-with-ggplot2.Rmd‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Although R is great for quickly turning data into plots, it is not widely used f
99

1010
Here I show five charts from the lay press that I use as examples in my data science courses. In the past I would show the originals, but I decided to replicate them in R to make it possible to generate class notes with just R code (there was a lot of googling involved).
1111

12-
Below I show the original figures followed by R code and the version of the plot it produces. I used the__ggplot2__ package but you can achieve similar results using other packages or even just with R-base. Any recommendations on how to improve the code or links to other good examples are welcomed. Please at to the comments or @ me on twitter:[@rafalab](https://twitter.com/rafalab).
12+
Below I show the original figures followed by R code and the version of the plot it produces. I used the__ggplot2__ package but you can achieve similar results using other packages or even just with R-base. Any recommendations on how to improve the code or links to other good examples are welcomed. Please at to the comments or @ me on twitter:[\@rafalab](https://twitter.com/rafalab).
1313

1414
##Example 1
1515

@@ -97,7 +97,7 @@ jet.colors <- colorRampPalette(c("#F0FFFF", "cyan", "#007FFF", "yellow", "#FFBF0
9797
9898
dat %>% mutate(state = reorder(state, desc(state))) %>%
9999
ggplot(aes(year, state, fill = rate)) +
100-
geom_tile(color = "white", size=0.35) +
100+
geom_tile(color = "white", size =0.35) +
101101
scale_x_continuous(expand = c(0,0)) +
102102
scale_fill_gradientn(colors = jet.colors(16), na.value = 'white') +
103103
geom_vline(xintercept = 1963, col = "black") +
@@ -108,7 +108,7 @@ dat %>% mutate(state = reorder(state, desc(state))) %>%
108108
ylab("") +
109109
xlab("") +
110110
theme(legend.position = "bottom", text = element_text(size = 8)) +
111-
annotate(geom = "text", x = 1963, y = 50.5, label = "Vaccine introduced", size = 3, hjust=0)
111+
annotate(geom = "text", x = 1963, y = 50.5, label = "Vaccine introduced", size = 3, hjust =0)
112112
```
113113

114114

@@ -194,17 +194,17 @@ tmp_3 <- map_df(1:3, function(i){
194194
tmp_2 %>%
195195
ggplot(aes(x, ymax = y, ymin = 0)) +
196196
geom_ribbon(fill = "grey") +
197-
facet_grid(candidate~., switch="y") +
197+
facet_grid(candidate~., switch ="y") +
198198
scale_x_continuous(breaks = seq(0, 75, 25), position = "top",
199-
label= paste0(seq(0, 75, 25), "%")) +
199+
label= paste0(seq(0, 75, 25), "%")) +
200200
geom_abline(intercept = 0, slope = 0) +
201201
xlab("") + ylab("") +
202202
theme_minimal() +
203203
theme(panel.grid.major.y = element_blank(),
204204
panel.grid.minor.y = element_blank(),
205-
axis.title.y=element_blank(),
206-
axis.text.y=element_blank(),
207-
axis.ticks.y=element_blank(),
205+
axis.title.y =element_blank(),
206+
axis.text.y =element_blank(),
207+
axis.ticks.y =element_blank(),
208208
strip.text.y = element_text(angle = 180, size = 11, vjust = 0.2)) +
209209
geom_ribbon(data = tmp_3, mapping = aes(x = x, ymax = y, ymin = 0, fill = candidate), inherit.aes = FALSE, show.legend = FALSE) +
210210
scale_fill_manual(values = c("#3cace4", "#fc5c34", "#fccc2c")) +

‎content/post/2019-08-28-you-can-replicate-almost-any-plot-with-ggplot2.html‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
<p>Although R is great for quickly turning data into plots, it is not widely used for making publication ready figures. But, with enough tinkering you can make almost any plot in R. For examples check out the<ahref="https://flowingdata.com/">flowingdata blog</a> or the<ahref="https://serialmentor.com/dataviz/index.html">Fundamentals of Data Visualization book</a>.</p>
1111
<p>Here I show five charts from the lay press that I use as examples in my data science courses. In the past I would show the originals, but I decided to replicate them in R to make it possible to generate class notes with just R code (there was a lot of googling involved).</p>
12-
<p>Below I show the original figures followed by R code and the version of the plot it produces. I used the<strong>ggplot2</strong> package but you can achieve similar results using other packages or even just with R-base. Any recommendations on how to improve the code or links to other good examples are welcomed. Please at to the comments or @ me on twitter:<spanclass="citation">[@rafalab]</span>(<ahref="https://twitter.com/rafalab"class="uri">https://twitter.com/rafalab</a>).</p>
12+
<p>Below I show the original figures followed by R code and the version of the plot it produces. I used the<strong>ggplot2</strong> package but you can achieve similar results using other packages or even just with R-base. Any recommendations on how to improve the code or links to other good examples are welcomed. Please at to the comments or @ me on twitter:<ahref="https://twitter.com/rafalab">@rafalab</a>.</p>
1313
<divid="example-1"class="section level2">
1414
<h2>Example 1</h2>
1515
<p>The first example is from<ahref="https://abcnews.go.com/blogs/headlines/2012/12/us-gun-ownership-homicide-rate-higher-than-other-developed-countries/">this</a> ABC news article. Here is the original:</p>
@@ -90,7 +90,7 @@ <h2>Example 3</h2>
9090

9191
dat %&gt;% mutate(state = reorder(state, desc(state))) %&gt;%
9292
ggplot(aes(year, state, fill = rate)) +
93-
geom_tile(color = &quot;white&quot;, size=0.35) +
93+
geom_tile(color = &quot;white&quot;, size =0.35) +
9494
scale_x_continuous(expand = c(0,0)) +
9595
scale_fill_gradientn(colors = jet.colors(16), na.value = &#39;white&#39;) +
9696
geom_vline(xintercept = 1963, col = &quot;black&quot;) +
@@ -101,7 +101,7 @@ <h2>Example 3</h2>
101101
ylab(&quot;&quot;) +
102102
xlab(&quot;&quot;) +
103103
theme(legend.position = &quot;bottom&quot;, text = element_text(size = 8)) +
104-
annotate(geom = &quot;text&quot;, x = 1963, y = 50.5, label = &quot;Vaccine introduced&quot;, size = 3, hjust=0)</code></pre>
104+
annotate(geom = &quot;text&quot;, x = 1963, y = 50.5, label = &quot;Vaccine introduced&quot;, size = 3, hjust =0)</code></pre>
105105
<p><imgsrc="/post/2019-08-28-you-can-replicate-almost-any-plot-with-ggplot2_files/figure-html/wsj-vaccines-example-1.png"width="100%"/></p>
106106
</div>
107107
<divid="example-4"class="section level2">
@@ -182,17 +182,17 @@ <h2>Example 5</h2>
182182
tmp_2 %&gt;%
183183
ggplot(aes(x, ymax = y, ymin = 0)) +
184184
geom_ribbon(fill = &quot;grey&quot;) +
185-
facet_grid(candidate~., switch=&quot;y&quot;) +
185+
facet_grid(candidate~., switch =&quot;y&quot;) +
186186
scale_x_continuous(breaks = seq(0, 75, 25), position = &quot;top&quot;,
187-
label= paste0(seq(0, 75, 25), &quot;%&quot;)) +
187+
label= paste0(seq(0, 75, 25), &quot;%&quot;)) +
188188
geom_abline(intercept = 0, slope = 0) +
189189
xlab(&quot;&quot;) + ylab(&quot;&quot;) +
190190
theme_minimal() +
191191
theme(panel.grid.major.y = element_blank(),
192192
panel.grid.minor.y = element_blank(),
193-
axis.title.y=element_blank(),
194-
axis.text.y=element_blank(),
195-
axis.ticks.y=element_blank(),
193+
axis.title.y =element_blank(),
194+
axis.text.y =element_blank(),
195+
axis.ticks.y =element_blank(),
196196
strip.text.y = element_text(angle = 180, size = 11, vjust = 0.2)) +
197197
geom_ribbon(data = tmp_3, mapping = aes(x = x, ymax = y, ymin = 0, fill = candidate), inherit.aes = FALSE, show.legend = FALSE) +
198198
scale_fill_manual(values = c(&quot;#3cace4&quot;, &quot;#fc5c34&quot;, &quot;#fccc2c&quot;)) +

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp