library(dplyr)
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
library(dplyr)
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
library(ggplot2)
library(RColorBrewer)
library(tidyverse)── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ forcats 1.0.0 ✔ stringr 1.5.1
✔ lubridate 1.9.3 ✔ tibble 3.2.1
✔ purrr 1.0.2 ✔ tidyr 1.3.1
✔ readr 2.1.5
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(dplyr)
setwd("C:/Users/brend/OneDrive/Desktop/New folder (2)")
nations <- read_csv("nations (1).csv")Rows: 5275 Columns: 10
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (5): iso2c, iso3c, country, region, income
dbl (5): year, gdp_percap, population, birth_rate, neonat_mortal_rate
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
nations <- nations %>%
mutate(gdp_trillions = (gdp_percap * population) / 10^12)selected_countries <- nations %>%
filter(country %in% c("China", "Germany", "Japan", "United States"))ggplot(selected_countries, aes(x = year, y = gdp_trillions, color = country)) +
geom_point() + # Add points
geom_line() + # Add lines connecting points
scale_color_brewer(palette = "Set1") + # Use the Set1 color palette from ColorBrewer
labs(title = "China's Rise to Become the Largest Economy",
x = "Year",
y = "GDP (Trillions of $)",
color = "Country") +
theme_minimal()