The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
Warning: package 'plotly' was built under R version 4.3.3
Loading required package: ggplot2
Warning: package 'ggplot2' was built under R version 4.3.3
Attaching package: 'plotly'
The following object is masked from 'package:ggplot2':
last_plot
The following object is masked from 'package:stats':
filter
The following object is masked from 'package:graphics':
layout
# Chart 1: GDP per Capita vs Life Expectancychart1_data <- gapminder %>%filter(year ==2007)p1 <-ggplot(chart1_data, aes(x = gdpPercap, y = lifeExp, color = continent, size = pop)) +geom_point(alpha =0.7) +scale_x_log10() +labs(title ="GDP per Capita vs Life Expectancy (2007)",x ="GDP per Capita (log scale)",y ="Life Expectancy")ggplotly(p1)
# Chart 2: Population Growth by Continentchart2_data <- gapminder %>%group_by(continent, year) %>%summarize(total_pop =sum(pop) /1e6)
`summarise()` has grouped output by 'continent'. You can override using the
`.groups` argument.
p2 <-ggplot(chart2_data, aes(x = year, y = total_pop, color = continent)) +geom_line(size =1) +labs(title ="Population Growth by Continent (1952-2007)",x ="Year",y ="Population (Millions)")
Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
ℹ Please use `linewidth` instead.
ggplotly(p2)
# Chart 3: Life Expectancy Over Time by Continentchart3_data <- gapminder %>%group_by(continent, year) %>%summarize(avg_lifeExp =mean(lifeExp))
`summarise()` has grouped output by 'continent'. You can override using the
`.groups` argument.
p3 <-ggplot(chart3_data, aes(x = year, y = avg_lifeExp, color = continent)) +geom_line(size =1) +labs(title ="Life Expectancy Over Time by Continent",x ="Year",y ="Average Life Expectancy")ggplotly(p3)