── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.2.1 ✔ readr 2.2.0
✔ forcats 1.0.1 ✔ stringr 1.6.0
✔ ggplot2 4.0.3 ✔ tibble 3.3.1
✔ lubridate 1.9.5 ✔ tidyr 1.3.2
✔ purrr 1.2.2
── 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)library(readr)library(ggplot2)
df<-read_csv("disease_democ.csv")
Rows: 168 Columns: 4
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (2): country, income_group
dbl (2): democ_score, infect_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.
head(df)
# A tibble: 6 × 4
country income_group democ_score infect_rate
<chr> <chr> <dbl> <dbl>
1 Bahrain High income: non-OECD 45.6 23
2 Bahamas, The High income: non-OECD 48.4 24
3 Qatar High income: non-OECD 50.4 24
4 Latvia High income: non-OECD 52.8 25
5 Barbados High income: non-OECD 46 26
6 Singapore High income: non-OECD 64 26
chart<-ggplot(df, aes(x= infect_rate, y = democ_score #, text= country, using text give the name of the country when selecting a point, but makes plotly remove a thing on the graph )) +labs(x="Infectious Disease Prevalence Score", y="Democratization Score",title="Comparison of Disease Prevalence and Democratization Score") +theme_minimal(base_family ="serif")chart
# Create a basic scatter plot p <-ggplot(gapminder, aes(gdp, life_expectancy, size = population, color = continent)) +geom_point(alpha =0.7) +scale_color_viridis_d() +scale_size(range =c(2, 12)) +scale_x_log10() +labs(title ="Year: {frame_time}", x ="GDP per capita", y ="Life expectancy" )p
Warning: Removed 2972 rows containing missing values or values outside the scale range
(`geom_point()`).
library(gifski)anim <- p +transition_time(year) +ease_aes("linear")animate(anim, renderer =gifski_renderer())
Warning: Removed 90 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 90 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 91 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 89 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 89 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 89 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 89 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 89 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 89 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 89 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 83 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 83 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 81 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 80 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 80 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 79 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 79 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 79 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 79 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 72 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 72 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 72 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 72 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 72 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 72 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 72 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 71 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 71 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 67 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 66 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 66 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 63 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 63 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 63 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 63 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 62 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 51 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 51 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 47 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 47 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 44 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 44 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 44 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 41 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 41 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 38 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 38 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 35 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 35 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 31 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 29 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 29 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 27 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 27 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 14 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 14 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 13 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 13 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 11 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 10 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 10 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 8 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 8 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 6 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 6 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 6 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 4 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 4 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 4 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 4 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 2 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 2 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 2 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 2 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 2 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 2 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 2 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 3 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 3 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 3 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 3 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 4 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 4 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 4 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 4 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 4 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 4 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 4 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 9 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 17 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 17 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 185 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 185 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 185 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 185 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 185 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 185 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 185 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 185 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 185 rows containing missing values or values outside the scale range
(`geom_point()`).
anim
Warning: Removed 90 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 90 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 91 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 89 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 89 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 89 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 89 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 89 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 89 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 89 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 83 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 83 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 81 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 80 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 80 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 79 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 79 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 79 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 79 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 72 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 72 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 72 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 72 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 72 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 72 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 72 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 71 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 71 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 67 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 66 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 66 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 63 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 63 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 63 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 63 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 62 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 51 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 51 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 47 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 47 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 44 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 44 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 44 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 41 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 41 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 38 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 38 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 35 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 35 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 31 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 29 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 29 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 27 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 27 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 14 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 14 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 13 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 13 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 11 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 10 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 10 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 8 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 8 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 6 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 6 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 6 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 4 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 4 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 4 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 4 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 2 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 2 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 2 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 2 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 2 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 2 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 2 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 3 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 3 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 3 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 3 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 4 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 4 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 4 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 4 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 4 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 4 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 4 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 9 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 17 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 17 rows containing missing values or values outside the scale range
(`geom_point()`).
Warning: Removed 185 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 185 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 185 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 185 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 185 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 185 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 185 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 185 rows containing missing values or values outside the scale range
(`geom_point()`).
Removed 185 rows containing missing values or values outside the scale range
(`geom_point()`).
library(highcharter) # for interactive charts
Registered S3 method overwritten by 'quantmod':
method from
as.zoo.data.frame zoo
Attaching package: 'highcharter'
The following object is masked from 'package:dslabs':
stars
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.
str(data)
tibble [5,275 × 11] (S3: tbl_df/tbl/data.frame)
$ iso2c : chr [1:5275] "AD" "AD" "AD" "AD" ...
$ iso3c : chr [1:5275] "AND" "AND" "AND" "AND" ...
$ country : chr [1:5275] "Andorra" "Andorra" "Andorra" "Andorra" ...
$ year : num [1:5275] 1996 1994 2003 1990 2009 ...
$ gdp_percap : num [1:5275] NA NA NA NA NA NA NA NA NA NA ...
$ population : num [1:5275] 64291 62707 74783 54511 85474 ...
$ birth_rate : num [1:5275] 10.9 10.9 10.3 11.9 9.9 NA 10.9 9.8 11.8 11.2 ...
$ neonat_mortal_rate: num [1:5275] 2.8 3.2 2 4.3 1.7 1.6 2 1.7 2.1 2.1 ...
$ region : chr [1:5275] "Europe & Central Asia" "Europe & Central Asia" "Europe & Central Asia" "Europe & Central Asia" ...
$ income : chr [1:5275] "High income" "High income" "High income" "High income" ...
$ gdp_tn : num [1:5275] NA NA NA NA NA NA NA NA NA NA ...
big4 <- data |>filter(iso3c %in%c("CHN","DEU", "JPN", "USA")) |>arrange(year)
`summarise()` has regrouped the output.
ℹ Summaries were computed grouped by year and region.
ℹ Output is grouped by year.
ℹ Use `summarise(.groups = "drop_last")` to silence this message.
ℹ Use `summarise(.by = c(year, region))` for per-operation grouping
(`?dplyr::dplyr_by`) instead.
# basic area chart, default optionshighchart () |>hc_add_series(data = regions,type ="area",hcaes(x = year,y = gdp_tn, group = region))
Rows: 47 Columns: 3
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (3): year, participants, costs
ℹ 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.
cols <-c("dodgerblue","orange") # set the color palette to dodger blue and orangehighchart() |>hc_yAxis_multiples(list(title =list(text ="Participants (millions)")),list(title =list(text ="Costs ($ billions)"),opposite =TRUE) ) |>hc_add_series(data = food_stamps$participants,name ="Participants (millions)",type ="column",yAxis =0) |>hc_add_series(data = food_stamps$costs,name ="Costs ($ billions)",type ="line",yAxis =1) |>hc_xAxis(categories = food_stamps$year,tickInterval =5) |>hc_colors(cols) |>hc_chart(style =list(fontFamily ="AvantGarde",fontWeight ="bold"))
Assignment
graph1<- data |>filter(iso3c %in%c("CHN","DEU", "JPN", "USA")) |>arrange(year) %>%ggplot(aes(year, gdp_tn, color= country)) +geom_point() +geom_line() +scale_color_brewer(palette ="Set1") +labs(title ="China's rise to become the largest economy") +theme_minimal()graph1
graph2<- data %>%group_by(region, year) %>%summarise(GDP =sum(gdp_tn, na.rm =TRUE)) %>%ggplot(aes(year, GDP, color= region)) +geom_area(aes(fill= region)) +scale_fill_brewer(palette ="Set2") +labs(title ="GDP by World bank region") +theme_classic()
`summarise()` has regrouped the output.
ℹ Summaries were computed grouped by region and year.
ℹ Output is grouped by region.
ℹ Use `summarise(.groups = "drop_last")` to silence this message.
ℹ Use `summarise(.by = c(region, year))` for per-operation grouping
(`?dplyr::dplyr_by`) instead.