forked from cb4ds/cxplot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeom_contour.Rmd
55 lines (42 loc) · 1.71 KB
/
geom_contour.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
---
title: "Geom Contour"
output: geom_contour
---
https://ggplot2.tidyverse.org/reference/geom_contour.html
```{r}
source('cxplot.r')
library(ggplot2)
library(dplyr)
library(canvasXpress)
```
```{r}
cxplot(ggplot(faithfuld, aes(waiting, eruptions, z = density)) + geom_contour())
```
```{r}
cxplot(ggplot(faithful, aes(waiting, eruptions)) + geom_density_2d())
```
```{r}
cxplot(ggplot(faithfuld, aes(waiting, eruptions, z = density)) + geom_contour_filled())
```
```{r}
cxplot(ggplot(faithfuld, aes(waiting, eruptions, z = density)) + geom_contour(bins = 5))
```
```{r}
cxplot(ggplot(faithfuld, aes(waiting, eruptions, z = density)) + geom_contour(binwidth = 0.001))
```
```{r}
cxplot(ggplot(faithfuld, aes(waiting, eruptions, z = density)) + geom_contour(colour = "red"))
```
```{r}
library(interp)
data(franke, package = "interp")
origdata <- as.data.frame(interp::franke.data(1, 1, franke))
grid <- with(origdata, interp::interp(x, y, z))
griddf <- subset(data.frame(x = rep(grid$x, nrow(grid$z)),
y = rep(grid$y, each = ncol(grid$z)),
z = as.numeric(grid$z)), !is.na(z))
cxplot(ggplot(griddf, aes(x, y, z = z)) + geom_contour_filled() + geom_point(data = origdata))
```
Add a new chunk by clicking the *Insert Chunk* button on the toolbar or by pressing *Cmd+Option+I*.
When you save the notebook, an HTML file containing the code and output will be saved alongside it (click the *Preview* button or press *Cmd+Shift+K* to preview the HTML file).
The preview shows you a rendered HTML copy of the contents of the editor. Consequently, unlike *Knit*, *Preview* does not run any R code chunks. Instead, the output of the chunk when it was last run in the editor is displayed.