Human Sciences

1 Relationship between area and population in Brazilian municipalities (EM13MAT405, EM13MAT407, EM13CHS101, EM13CHS104, EM13CNT301)

url <- "https://raw.githubusercontent.com/turicas/rows/refs/heads/develop/examples/data/brazilian-cities.csv" # define the link to the data
data <- read.csv(url) # read the data file

library(plotly)
plot_ly(data, x = ~area, y = ~inhabitants,
type = "scatter", mode = 'markers',
marker = list(line = list(width = 1)),
text = ~paste("City: ", city, "<br>State: ", state), # Text on hover
hoverinfo = 'text', # Show only the defined text
frame = ~state)%>%
layout(
title = "Area and population distribution in Brazilian cities",
xaxis = list(title = "States", type = "log"),
yaxis = list(title = "Population", type = "log"),
showlegend = FALSE
) %>%
animation_opts(
frame = 500, # Animation speed
transition = 0,
redraw = FALSE
)

Suggestions:

Try modifying the graph, using/replacing alternatively the commands below in the code snippet:
layout(
title = "Area and Population Distribution in Brazilian Cities",
xaxis = list(title = "Area (log)", type = "log"), # Logarithmic scale
yaxis = list(title = "Population (log)", type = "log"),
showlegend = FALSE
) %>%


2 Population alcohol consumption in 2010 (EM13CHS301, EM13CNT205)

library(plotly)

# Example of dataframe with dummy values
df <- read.csv("https://raw.githubusercontent.com/plotly/datasets/refs/heads/master/2010_alcohol_consumption_by_country.csv")

# Creating the choropleth map with the adjusted color scale
plot_ly(
data = df,
locations = ~location,
locationmode = "country names",
z = ~alcohol, # Variable that determines the colors
type = "choropleth",
colorscale = "Viridis") # other scales: # other scales: RdBu, Inferno, Blues, Cividis, Greens, ...

Suggestions:

Try modifying the graph, using/replacing the commands below in the code snippet:
# Color change
colorscale = "Blues"


3 Greenhouse effect and CO\(_{2}\) emissions in Brazil (EM13CN09, EM13CHS104)

library(plotly)
library(magrittr) # required libraries
# 1) Getting data from the internet
url <- "https://raw.githubusercontent.com/datasets/global-temp/refs/heads/main/data/annual.csv" # define the link to the data
data <- read.csv(url) # read the data file

# 2) Building the graph with animation

plot_ly(data, x = ~Year, y = ~Mean,
type = "bar",
marker = list(line = list(width = 10)),
frame = ~Year) %>%
animation_opts(
frame = 150, # Animation speed
transition = 0,
redraw = TRUE
) %>%
layout(
title = "Global Temperature Fluctuation",
xaxis = list(title = "Years"),
yaxis = list(title = "Temperature Difference, C"))

Suggestions:

Try modifying the graph, using/replacing the commands below in the code snippet:
frame = 100, # Adjusted animation speed


4 Global oil production in 2014 (in teraWatts)

Note: Crude oil, shale oil, tar sands, condensates, and natural gas liquids - ethane, LPG and naphtha separated from natural gas production.

Suggestions:

Try modifying the graph, using/replacing the commands below in the code snippet:
library(plotly)

# Example of dataframe with dummy values
df <- read.csv("https://raw.githubusercontent.com/owid/owid-datasets/refs/heads/master/datasets/Oil%20production%20-%20Etemad%20%26%20Luciana/Oil%20production%20-%20Etemad%20%26%20Luciana.csv")

# Renaming the columns to make them easier to interpret and plot

names(df) <- c("Country", "Year", "Production.TeraWatt")

# Filtering the data for the last year (2014)
df <- subset(df, Year == "2014")

# Creating the choropleth map with the adjusted color scale
library(plotly)
plot_ly(
data = df,
locations = ~Country,
locationmode = "country names",
z = ~Production.TeraWatt, # Variable that determines the colors
type = "choropleth",
colorscale = "RdBu") # other scales: # other scales: Viridis, Inferno, Blues, Cividis, Greens, ...


5 Global Warming (EM13CN03, EM13CN09, EM13CHS105, EM13CHS205)

library(plotly)
library(magrittr) # required libraries

# 1) Getting the data from the internet

url <- "https://raw.githubusercontent.com/datasets/global-temp/refs/heads/main/data/annual.csv" # define the link to the data
data <- read.csv(url) # read the data file

# 2) Building the graph with animation

plot_ly(data, x = ~Year, y = ~Mean,
type = "bar",
marker = list(line = list(width = 10)),
frame = ~Year) %>%
animation_opts(
frame = 150, # Animation speed
transition = 0,
redraw = TRUE
) %>%
layout(
title = "Global Temperature Fluctuation",
xaxis = list(title = "Years"),
yaxis = list(title = "Temperature Difference, C"))

Suggestions:

Try modifying the graph, using/replacing alternatively the commands below in the code snippet:
plot_ly(data, x = ~Year, y = ~Mean, type = "bar",
text = ~paste("Year:", Year, "<br>Temperature:", Mean, "°C"),
hoverinfo = "text")


6 Life expectancy and Gross Domestic Product - GDP, 1956 to 2007 (EM13CHS101, EM13CHS104, EM13MAT405, EM13MAT410)

library(plotly)

# Getting the data from the internet
url <- read.csv("https://raw.githubusercontent.com/kirenz/datasets/refs/heads/master/gapminder.csv")

dadosExpida <- url # assigning the data to an `R` object

# Creating the interactive graph with animation
plot_ly(
dadosExpida, # data converted from the internet
x = ~gdpPercap, # per capita income
y = ~lifeExp, # life expectancy
size = ~pop, # size of the points as a function of the population
color = ~country, # color of the points as a function of the country
frame = ~year, # Frame for the animation by year of data collection
text = ~continent, # Country as information when hovering the mouse
hoverinfo = "text", type = 'scatter', # chart type
mode = 'markers',
marker = list(sizemode = 'diameter', opacity = 0.7)
) %>%
layout( # assigning title and axis labels
title = "Gross Domestic Product X Life Expectancy",
xaxis = list(title = "GDP (log), US$", type = "log"),
yaxis = list(title = "Life Expectancy, years"),
showlegend = TRUE # whether or not to display the legend
) %>%
animation_opts(
frame = 1000, # Animation speed
transition = 0,
redraw = TRUE
)

Suggestions:

Try modifying the graph, using/replacing alternatively the commands below in the code snippet:
# Inside plot_ly()
color = ~continent


7 Meteorite fall on Earth - 1800 to 2013 (EM13CHS101, EM13CNT303, EM13CNT301)

library(ggplot2)
library(plotly)
library(dplyr)
library(maps)

meteoritos <- readr::read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2019/2019-06-11/meteorites.csv")

options(scipen = 999) 

meteoritos_Mundo <- meteoritos %>%
  filter(fall == "Fell") %>%
  filter(year > 1800) %>%
  # drop_na() %>%
  arrange(mass)

# Carregar o mapa do mundo
world <- map_data("world")

mapa_animado <- world %>%
  ggplot() +
  geom_polygon(aes( x= long, y = lat, group = group),
               fill = "grey20",
               color = "white",
               size = 0.01) +
  geom_point(data= meteoritos_Mundo, 
             aes(x = long, 
                 y = lat, 
                 frame = year,
                 size = mass),
             color = "orange",
             alpha = 0.7) +
  labs( title = "Queda de meteoritos -  1800 a 2013}",
        caption = "The Meteoritical Society") +
  # theme_map() +
  scale_size_continuous(guide = F) +
  scale_color_discrete(name = "Type") +
  theme(plot.title = element_text(size = 10, hjust = 0.5))


fig_2 <- ggplotly(mapa_animado) %>% animation_slider(currentvalue = list(prefix = "Year ", font = list(color="orange"))) 

fig_2

Suggestions:

Try modifying the graph, using/replacing alternatively the commands below in the code snippet:
fill = "grey30", # Changed from "grey20" to "grey30"


Back to top