Skip to content

Commit

Permalink
correction erreur
Browse files Browse the repository at this point in the history
  • Loading branch information
linogaliana committed Dec 8, 2021
1 parent 6474746 commit 41c8986
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions content/course/modelisation/0_preprocessing.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,11 @@ l'une des surcouches à JavaScript vue dans la partie [visualisation](#visualisa

En l'occurrence, on peut utiliser `plotly` pour tenir compte de la population:

{{< chart data="../course/modelisation/people_vote" >}}

La Figure a été obtenue avec le code suivant:

```{python, include = TRUE, echo=TRUE}
```{python, message = FALSE, echo=TRUE, warning = FALSE}
import plotly
import plotly.graph_objects as go
import pandas as pd
Expand All @@ -185,9 +188,7 @@ centroids = pd.DataFrame(centroids[["county_name",'lon','lat','winner', 'CENSUS_
groups = centroids.groupby('winner')
df = centroids.copy()
```
```{python, include = TRUE, echo=TRUE}
df['color'] = df['winner'].replace(color_dict)
df['size'] = df['CENSUS_2010_POP']/6000
df['text'] = df['CENSUS_2010_POP'].astype(int).apply(lambda x: '<br>Population: {:,} people'.format(x))
Expand All @@ -202,9 +203,7 @@ fig_plotly = go.Figure(data=go.Scattergeo(
marker_size = df['size'],
hoverinfo="text"
))
```
```{python, include = TRUE, echo=TRUE}
fig_plotly.update_traces(
marker = {'opacity': 0.5, 'line_color': 'rgb(40,40,40)', 'line_width': 0.5, 'sizemode': 'area'}
)
Expand All @@ -213,7 +212,6 @@ fig_plotly.update_layout(
title_text = "Reproduction of the \"Acres don't vote, people do\" map <br>(Click legend to toggle traces)",
showlegend = True,
geo = {"scope" = 'usa', "landcolor" = 'rgb(217, 217, 217)'}
)
)
```

Expand All @@ -222,7 +220,6 @@ fig_plotly.update_layout(
fig_plotly.write_json("people_vote.json")
```

{{< chart data="../course/modelisation/people_vote" >}}


## Explorer la structure des données
Expand Down

0 comments on commit 41c8986

Please sign in to comment.