Skip to content

Commit b825999

Browse files
committed
fix
1 parent 72bcc6f commit b825999

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

_posts/ggplot2/2019-08-06-geom_density_2d.Rmd

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ packageVersion('plotly')
4242
Source: [Brett Carpenter from Data.World](https://data.world/brettcarpenter/craft-beer-data)
4343

4444
```{r, results='hide'}
45+
library(plotly)
4546
beers <- read.csv("https://raw.githubusercontent.com/plotly/datasets/master/beers.csv", stringsAsFactors = FALSE)
4647
4748
p <- ggplot(beers, aes(x=abv, y=ibu)) +
@@ -65,6 +66,9 @@ chart_link
6566
Since each of the lines (in the above graph) shows a different "level", setting "fill = stat(level)" allows for a filled graph.
6667

6768
```{r, results='hide'}
69+
library(plotly)
70+
beers <- read.csv("https://raw.githubusercontent.com/plotly/datasets/master/beers.csv", stringsAsFactors = FALSE)
71+
6872
p <- ggplot(beers, aes(x=abv, y=ibu)) +
6973
stat_density_2d(aes(fill = stat(level)), geom="polygon") +
7074
labs(y = "bitterness (IBU)",
@@ -84,7 +88,11 @@ chart_link
8488

8589
### Preset Colourscale
8690
["Viridis" colourscales](https://ggplot2.tidyverse.org/reference/scale_viridis.html) are designed to still be perceptible in black-and-white, as well as for those with colourblindness. It comes with five colourscales, selected using the option= parameter: "magma" (or "A"), "inferno" (or "B"), "plasma" (or "C"), "viridis" (or "D", the default), and "cividis" (or "E").
91+
8792
```{r, results='hide'}
93+
library(plotly)
94+
beers <- read.csv("https://raw.githubusercontent.com/plotly/datasets/master/beers.csv", stringsAsFactors = FALSE)
95+
8896
p <- ggplot(beers, aes(x=abv, y=ibu)) +
8997
stat_density_2d(aes(fill = stat(level)), geom="polygon") +
9098
scale_fill_viridis_c(option = "plasma") +
@@ -107,6 +115,9 @@ chart_link
107115
### Customized Colourscale
108116
You can also set your own colour gradients by defining a high and low point.
109117
```{r, results='hide'}
118+
library(plotly)
119+
beers <- read.csv("https://raw.githubusercontent.com/plotly/datasets/master/beers.csv", stringsAsFactors = FALSE)
120+
110121
p <- ggplot(beers, aes(x=abv, y=ibu)) +
111122
stat_density_2d(aes(fill = stat(level)), geom="polygon") +
112123
scale_fill_gradient(low = "lightskyblue1", high = "darkred") +
@@ -130,7 +141,9 @@ chart_link
130141
I use variable "style2" to filter out the six most common beer styles. This way, we can see that the cluster of beers in the top right (i.e. more bitter and higher alcohol content) are IPAs - perhaps unsurprisingly.
131142

132143
```{r, results='hide'}
144+
library(plotly)
133145
library(dplyr)
146+
beers <- read.csv("https://raw.githubusercontent.com/plotly/datasets/master/beers.csv", stringsAsFactors = FALSE)
134147
135148
p <- ggplot(beers, aes(x=abv, y=ibu)) +
136149
geom_density_2d(alpha=0.5) +

_posts/ggplot2/2019-08-06-geom_density_2d.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Source: [Brett Carpenter from Data.World](https://data.world/brettcarpenter/craf
4444

4545

4646
```r
47+
library(plotly)
4748
beers <- read.csv("https://raw.githubusercontent.com/plotly/datasets/master/beers.csv", stringsAsFactors = FALSE)
4849

4950
p <- ggplot(beers, aes(x=abv, y=ibu)) +
@@ -66,6 +67,9 @@ Since each of the lines (in the above graph) shows a different "level", setting
6667

6768

6869
```r
70+
library(plotly)
71+
beers <- read.csv("https://raw.githubusercontent.com/plotly/datasets/master/beers.csv", stringsAsFactors = FALSE)
72+
6973
p <- ggplot(beers, aes(x=abv, y=ibu)) +
7074
stat_density_2d(aes(fill = stat(level)), geom="polygon") +
7175
labs(y = "bitterness (IBU)",
@@ -85,6 +89,9 @@ chart_link
8589
["Viridis" colourscales](https://ggplot2.tidyverse.org/reference/scale_viridis.html) are designed to still be perceptible in black-and-white, as well as for those with colourblindness. It comes with five colourscales, selected using the option= parameter: "magma" (or "A"), "inferno" (or "B"), "plasma" (or "C"), "viridis" (or "D", the default), and "cividis" (or "E").
8690

8791
```r
92+
library(plotly)
93+
beers <- read.csv("https://raw.githubusercontent.com/plotly/datasets/master/beers.csv", stringsAsFactors = FALSE)
94+
8895
p <- ggplot(beers, aes(x=abv, y=ibu)) +
8996
stat_density_2d(aes(fill = stat(level)), geom="polygon") +
9097
scale_fill_viridis_c(option = "plasma") +
@@ -106,6 +113,9 @@ chart_link
106113
You can also set your own colour gradients by defining a high and low point.
107114

108115
```r
116+
library(plotly)
117+
beers <- read.csv("https://raw.githubusercontent.com/plotly/datasets/master/beers.csv", stringsAsFactors = FALSE)
118+
109119
p <- ggplot(beers, aes(x=abv, y=ibu)) +
110120
stat_density_2d(aes(fill = stat(level)), geom="polygon") +
111121
scale_fill_gradient(low = "lightskyblue1", high = "darkred") +
@@ -128,7 +138,9 @@ I use variable "style2" to filter out the six most common beer styles. This way,
128138

129139

130140
```r
141+
library(plotly)
131142
library(dplyr)
143+
beers <- read.csv("https://raw.githubusercontent.com/plotly/datasets/master/beers.csv", stringsAsFactors = FALSE)
132144

133145
p <- ggplot(beers, aes(x=abv, y=ibu)) +
134146
geom_density_2d(alpha=0.5) +

0 commit comments

Comments
 (0)