Bishwajit Ghose

Month: April 2024

test post

# gapminder
import plotly_express as px
import pandas as pd
pd.plotting.register_matplotlib_converters()
import matplotlib.pyplot as plt
%matplotlib inline
import seaborn as sns
import numpy as np

from gapminder import gapminder
gapminder.head()

Visualizing gapminder data in python

# gapminder
import plotly_express as px
import pandas as pd
pd.plotting.register_matplotlib_converters()
import matplotlib.pyplot as plt
%matplotlib inline
import seaborn as sns
import numpy as np

from gapminder import gapminder
gapminder.head()


#scatter
fig = px.scatter(gapminder,
                 x="Income",
                 y="Life Expectancy",
                 size="Population",
                 size_max=60,
                 color="Region",
                 hover_name="Country",
                 facet_col="Income Level",
                 color_discrete_sequence=["#FF69B4", "#87CEFA",
                                          "#FFFF00", "#32CD32"],
                 range_y=[50, 90],
                 width=1000,
                 labels={"Income": "Income in $s",
                         "Life Expectancy": "Life Expectancy in years"},
                 title="World Map for Health and Wealth (data from 2018)",
                 opacity=1
                 )

fig.layout.xaxis1.update(matches=None)
fig.layout.xaxis2.update(matches=None)
fig.layout.xaxis3.update(matches=None)
fig.layout.xaxis4.update(matches=None)
py.iplot(fig, sharing='public', filename='factfulness_bubble_chart_2018')

p.head()

Recoding in R

Recoding in R refers to the process of transforming or modifying the values of a variable. This can involve changing the values to different categories, recategorizing them, or assigning new values based on specific conditions.

#mutate province names
dd= dd1 %>%
  mutate(geo = case_when(
    grepl("Newfoundland and Labrador", geo) ~ "Newfoundland and Labrador",
    grepl("Nova Scotia", geo) ~ "Nova Scotia",
    grepl("Prince Edward Island", geo) ~ "Prince Edward Island",
    grepl("New Brunswick", geo) ~ "New Brunswick",
    grepl("Quebec", geo) ~ "Quebec",
    grepl("Onta", geo) ~ "Ontario",
    grepl("Manitoba", geo) ~ "Manitoba",
    grepl("Saskatchewan", geo) ~ "Saskatchewan",
    grepl("Alberta", geo) ~ "Alberta",
    grepl("British Columbia", geo) ~ "British Columbia",
    grepl("Canada", geo) ~ "Canada",
    TRUE ~ "Other"
  )) %>%
  group_by(across(c(1:4))) %>%
  summarise(value = sum(value))