-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathgraph.Rmd
executable file
·35 lines (25 loc) · 975 Bytes
/
graph.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
---
title: "statar"
author: "Matthieu Gomez"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Graph}
%\VignetteEngine{knitr::rmarkdown}
%\usepackage[utf8]{inputenc}
---
## stat_binmean
`stat_binmean()` is a `stat` for ggplot2. It returns the mean of `y` and `x` within bins of `x`. It's a bareborne version of the Stata command [binscatter](https://github.com/michaelstepner/binscatter)
```R
ggplot(iris, aes(x = Sepal.Width , y = Sepal.Length)) + stat_binmean()
```
<img src="output_2_0.png" height = "400">
```R
ggplot(iris, aes(x = Sepal.Width , y = Sepal.Length, color = Species)) + stat_binmean(n=10)
```
<img src="output_3_0.png" height = "400">
Since `stat_binmean` is just a layer for ggplo2, you can surimpose any model fit
```R
ggplot(iris, aes(x = Sepal.Width , y = Sepal.Length, color = Species)) + stat_binmean(n=10) + stat_smooth(method = "lm", se = FALSE)
```
<img src="output_4_0.png" height = "400">