Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 06691ab

Browse files
committed
final version of geom_bin2d, and also finally fixed the initial test edits
1 parent 12978e1 commit 06691ab

File tree

4 files changed

+21
-100
lines changed

4 files changed

+21
-100
lines changed

2017-04-21-geom_quantile.md

Lines changed: 0 additions & 77 deletions
This file was deleted.

_posts/ggplot2/2017-04-21-geom_quantile.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ output:
1717

1818

1919

20-
### New to Plotly??!!?
20+
### New to Plotly?
2121

2222
Plotly's R library is free and open source!<br>
2323
[Get started](https://plot.ly/r/getting-started/) by downloading the client and [reading the primer](https://plot.ly/r/getting-started/).<br>
2424
You can set up Plotly to work in [online](https://plot.ly/r/getting-started/#hosting-graphs-in-your-online-plotly-account) or [offline](https://plot.ly/r/offline/) mode.<br>
2525
We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-documentation/images/r_cheat_sheet.pdf) (new!) to help you get started!
26-
2017-04-21-geom_quantile.Rmd
26+
2727
### Version Check
2828

2929
Version 4 of Plotly's R package is now [available](https://plot.ly/r/getting-started/#installation)!<br>

_posts/ggplot2/2019-07-12-geom_bin2d.Rmd

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
title: geom_bin2d | Examples | Plotly
33
name: geom_bin2d
44
permalink: ggplot2/geom_bin2d/
5-
description: How to make a bar chart in ggplot2 using geom_bin2d. Examples of filled and facetted bar charts. [UPDATE]
5+
description: How to make a 2-dimensional heatmap in ggplot2 using geom_bin2d. Examples of coloured and facetted graphs.
66
layout: base
7-
thumbnail: thumbnail/bar.jpg [ADD]
7+
thumbnail: thumbnail/geom_bin2d.jpg
88
language: ggplot2
99
page_type: example_index
1010
has_thumbnail: true
11-
display_as: basic
11+
display_as: statistical
1212
order: 2
1313
output:
1414
html_document:
@@ -47,7 +47,7 @@ english_french <- read.csv("https://raw.githubusercontent.com/plotly/datasets/ma
4747
4848
p <- ggplot(english_french, aes(x=engperc,y=frenperc)) +
4949
geom_bin2d() +
50-
labs(title = "Distribution of Canadian towns by English and French fluency",
50+
labs(title = "Distribution of Canadian areas by English and French fluency",
5151
x = "% fluent in English",
5252
y = "% fluent in French",
5353
fill = "# of census \nsubdivisions")
@@ -65,7 +65,7 @@ chart_link
6565

6666
### Customized Colours
6767
The automatic colour scheme is unintuitive: lighter colours denote larger numbers than darker colours.
68-
We should change that, and while we're at it, make the colour scale logarithmic.
68+
We should change that by setting our own colour scale. We should also move to a logarithmic scale, since as it is, the very large value in the bottom right overshadows all other values.
6969

7070
```{r, results='hide'}
7171
library(plotly)
@@ -81,7 +81,7 @@ ggplotly(p)
8181
8282
# Create a shareable link to your chart
8383
# Set up API credentials: https://plot.ly/r/getting-started
84-
chart_link = api_create(p, filename="geom_bin2d/coloured-chart")
84+
chart_link = api_create(p, filename="geom_bin2d/log-chart")
8585
chart_link
8686
```
8787

@@ -97,7 +97,6 @@ library(plotly)
9797
9898
p <- ggplot(english_french, aes(x=engperc, y=frenperc, weight=total)) +
9999
geom_bin2d() +
100-
geom_bin2d(data = transform(english_french,region = "All"),bins = 20) +
101100
scale_fill_gradient(low="lightblue1",high="darkblue",trans="log10") +
102101
labs(title = "Distribution of the Canadian population by English and French fluency",
103102
x = "% fluent in English",
@@ -117,7 +116,7 @@ chart_link
117116
```
118117

119118
### With Facets
120-
We can facet the graphic with the "region" column. We can also use a little trick to add an "All" subset containing all the data.
119+
We can facet the graphic with the "region" column, and set "bins" to 20, so that the graph is 20 x 20 sides. We can also use a little trick to add an "All" subset containing all the data.
121120

122121
```{r, results='hide'}
123122
library(plotly)
@@ -130,7 +129,7 @@ p <- ggplot(english_french, aes(x=engperc,y=frenperc, weight=total)) +
130129
labs(title = "Distribution of Canadian towns by English and French fluency",
131130
x = "% fluent in English",
132131
y = "% fluent in French",
133-
fill = "# of census \nsubdivisions")
132+
fill = "# of people")
134133
ggplotly(p)
135134
136135
@@ -158,7 +157,7 @@ p <- ggplot(english_french, aes(x=engperc,y=frenperc, weight=total)) +
158157
labs(title = "Distribution of Canadian towns by English and French fluency",
159158
x = "% fluent in English",
160159
y = "% fluent in French",
161-
fill = "# of census \nsubdivisions") +
160+
fill = "# of people") +
162161
theme_bw() +
163162
theme(text = element_text(family = 'Fira Sans'))
164163
ggplotly(p)

_posts/ggplot2/2019-07-12-geom_bin2d.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
title: geom_bin2d | Examples | Plotly
33
name: geom_bin2d
44
permalink: ggplot2/geom_bin2d/
5-
description: How to make a bar chart in ggplot2 using geom_bin2d. Examples of filled and facetted bar charts. [UPDATE]
5+
description: How to make a 2-dimensional heatmap in ggplot2 using geom_bin2d. Examples of coloured and facetted graphs.
66
layout: base
7-
thumbnail: thumbnail/bar.jpg [ADD]
7+
thumbnail: thumbnail/geom_bin2d.jpg
88
language: ggplot2
99
page_type: example_index
1010
has_thumbnail: true
11-
display_as: basic
11+
display_as: statistical
1212
order: 2
1313
output:
1414
html_document:
@@ -49,7 +49,7 @@ english_french <- read.csv("https://raw.githubusercontent.com/plotly/datasets/ma
4949

5050
p <- ggplot(english_french, aes(x=engperc,y=frenperc)) +
5151
geom_bin2d() +
52-
labs(title = "Distribution of Canadian towns by English and French fluency",
52+
labs(title = "Distribution of Canadian areas by English and French fluency",
5353
x = "% fluent in English",
5454
y = "% fluent in French",
5555
fill = "# of census \nsubdivisions")
@@ -65,7 +65,7 @@ chart_link
6565

6666
### Customized Colours
6767
The automatic colour scheme is unintuitive: lighter colours denote larger numbers than darker colours.
68-
We should change that, and while we're at it, make the colour scale logarithmic.
68+
We should change that by setting our own colour scale. We should also move to a logarithmic scale, since as it is, the very large value in the bottom right overshadows all other values.
6969

7070

7171
```r
@@ -82,11 +82,11 @@ ggplotly(p)
8282

8383
# Create a shareable link to your chart
8484
# Set up API credentials: https://plot.ly/r/getting-started
85-
chart_link = api_create(p, filename="geom_bin2d/coloured-chart")
85+
chart_link = api_create(p, filename="geom_bin2d/log-chart")
8686
chart_link
8787
```
8888

89-
<iframe src="https://plot.ly/~RPlotBot/5676.embed" width="800" height="600" id="igraph" scrolling="no" seamless="seamless" frameBorder="0"> </iframe>
89+
<iframe src="https://plot.ly/~RPlotBot/5682.embed" width="800" height="600" id="igraph" scrolling="no" seamless="seamless" frameBorder="0"> </iframe>
9090

9191
### Weighted Data
9292
In the previous graphs, each observation represented a single census subdivision - this counted small towns of 500 people equally with cities like Montreal and Toronto. We can weight the data by the "total" column (i.e. total population) to make this a graph of population.
@@ -97,7 +97,6 @@ library(plotly)
9797

9898
p <- ggplot(english_french, aes(x=engperc, y=frenperc, weight=total)) +
9999
geom_bin2d() +
100-
geom_bin2d(data = transform(english_french,region = "All"),bins = 20) +
101100
scale_fill_gradient(low="lightblue1",high="darkblue",trans="log10") +
102101
labs(title = "Distribution of the Canadian population by English and French fluency",
103102
x = "% fluent in English",
@@ -115,7 +114,7 @@ chart_link
115114
<iframe src="https://plot.ly/~RPlotBot/5680.embed" width="800" height="600" id="igraph" scrolling="no" seamless="seamless" frameBorder="0"> </iframe>
116115

117116
### With Facets
118-
We can facet the graphic with the "region" column. We can also use a little trick to add an "All" subset containing all the data.
117+
We can facet the graphic with the "region" column, and set "bins" to 20, so that the graph is 20 x 20 sides. We can also use a little trick to add an "All" subset containing all the data.
119118

120119

121120
```r
@@ -129,7 +128,7 @@ p <- ggplot(english_french, aes(x=engperc,y=frenperc, weight=total)) +
129128
labs(title = "Distribution of Canadian towns by English and French fluency",
130129
x = "% fluent in English",
131130
y = "% fluent in French",
132-
fill = "# of census \nsubdivisions")
131+
fill = "# of people")
133132
ggplotly(p)
134133

135134

@@ -156,7 +155,7 @@ p <- ggplot(english_french, aes(x=engperc,y=frenperc, weight=total)) +
156155
labs(title = "Distribution of Canadian towns by English and French fluency",
157156
x = "% fluent in English",
158157
y = "% fluent in French",
159-
fill = "# of census \nsubdivisions") +
158+
fill = "# of people") +
160159
theme_bw() +
161160
theme(text = element_text(family = 'Fira Sans'))
162161
ggplotly(p)

0 commit comments

Comments
 (0)