---
title: "Tableau de bord"
author: "Ousmane Diop"
output:
flexdashboard::flex_dashboard:
orientation: rows
social: menu
source_code: embed
---
```{r setup, include=FALSE}
library(ggplot2)
library(plotly)
library(plyr)
library(flexdashboard)
# create some data
set.seed(955)
dat <- data.frame(cond = rep(c("A", "B"), each=10),
xvar = 1:20 + rnorm(20,sd=3),
yvar = 1:20 + rnorm(20,sd=3))
```
PAGE 1
=======================================================================
Row
------------------------------------------------------------------------
### Diagramme de dispersion avec geom_point
```{r}
p <- ggplot(dat,aes(x=xvar, y=yvar))+geom_point(shape =1)
ggplotly(p)
```
### Régression Linéaire avec geom_smooth
```{r}
p <- ggplot(dat,aes(x=xvar, y=yvar))+
geom_point(shape =1)+
geom_smooth(method =lm)
ggplotly(p)
```
Row
-----------------------------------------------------------------------
### geom_smooth avec ajustement lissé Loess
```{r}
p <- ggplot(dat,aes(x=xvar, y=yvar))+
geom_point(shape =1)+
geom_smooth()
ggplotly(p)
```
### Contrainte de pente avec stat_smooth
```{r}
n <- 20
x1 <- rnorm(n); x2 <- rnorm(n)
y1 <- 2 * x1 + rnorm(n)
y2 <- 3 * x2 + (2 + rnorm(n))
A <- as.factor(rep(c(1, 2), each = n))
df <- data.frame(x = c(x1, x2), y = c(y1, y2), A = A)
fm <- lm(y ~ x + A, data = df)
pred <- predict(fm)
dat1 <- cbind(df, pred)
p <- ggplot(dat1,aes(x = x, y = y, color = A))
p <- p + geom_point() + geom_line(aes(y = pred))
ggplotly(p)
```
PAGE 2
=======================================================================
Row
-----------------------------------------------------------------------
### Exemple avec stat_density
```{r}
dfGamma = data.frame(nu75 = rgamma(100, 0.75),
nu1 = rgamma(100, 1),
nu2 = rgamma(100, 2))
dfGamma = stack(dfGamma)
p <- ggplot(dfGamma, aes(x = values)) +
stat_density(aes(group = ind, color = ind),position="identity",geom="line")
ggplotly(p)
```
### Ajouter une courbe de densité conditionnelle pour le graph
```{r}
p <- ggplot(dat, aes(x=xvar, y=yvar)) +
geom_point(shape=1) # Use hollow circles
ggplotly(p)
```
Row
-----------------------------------------------------------------------
### geom_density et facet_wrap ensembles
```{r}
dd<-data.frame(matrix(rnorm(144, mean=2, sd=2),72,2),c(rep("A",24),rep("B",24),rep("C",24)))
colnames(dd) <- c("x_value", "Predicted_value", "State_CD")
dd <- data.frame(
predicted = rnorm(72, mean = 2, sd = 2),
state = rep(c("A", "B", "C"), each = 24)
)
library('plyr')
grid <- with(dd, seq(min(predicted), max(predicted), length = 100))
normaldens <- ddply(dd, "state", function(df) {
data.frame(
predicted = grid,
density = dnorm(grid, mean(df$predicted), sd(df$predicted))
)
})
p <- ggplot(dd, aes(predicted)) +
geom_density() +
geom_line(aes(y = density), data = normaldens, colour = "red") +
facet_wrap(~ state)
ggplotly(p)
```
### Superposition densité et nuages de points via geom_demsity
```{r}
df <- data.frame(x <- rchisq(1000, 10, 10),
y <- rnorm(1000))
p <- ggplot(df, aes(x, y)) +
geom_point(alpha = 0.5) +
geom_density_2d() +
theme(panel.background = element_rect(fill = '#ffffff'))
ggplotly(p)
```