library(ggplot2)
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.2.1     ✔ readr     2.2.0
✔ forcats   1.0.1     ✔ stringr   1.6.0
✔ lubridate 1.9.5     ✔ tibble    3.3.1
✔ purrr     1.2.2     ✔ tidyr     1.3.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
disease_democ <- read_csv("C:/Users/akeeb/Downloads/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.
tail(disease_democ)
# A tibble: 6 × 4
  country       income_group        democ_score infect_rate
  <chr>         <chr>                     <dbl>       <dbl>
1 Turkey        Upper middle income        54.8          39
2 Panama        Upper middle income        46            40
3 Gabon         Upper middle income        34.6          41
4 Venezuela, RB Upper middle income        41.6          42
5 Colombia      Upper middle income        44.8          43
6 Brazil        Upper middle income        37.2          45
head(disease_democ)
# 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
names(disease_democ)
[1] "country"      "income_group" "democ_score"  "infect_rate" 

Activity 1

There are 5 groups outputted with the line of code.

unique(disease_democ$income_group)
[1] "High income: non-OECD" "High income: OECD"     "Low income"           
[4] "Lower middle income"   "Upper middle income"  

Activity 2

disease_democ |> filter(country == "Qatar")|>pull(income_group)
[1] "High income: non-OECD"
names(postscriptFonts())
 [1] "serif"                "sans"                 "mono"                
 [4] "AvantGarde"           "Bookman"              "Courier"             
 [7] "Helvetica"            "Helvetica-Narrow"     "NewCenturySchoolbook"
[10] "Palatino"             "Times"                "URWGothic"           
[13] "URWBookman"           "NimbusMon"            "NimbusSan"           
[16] "URWHelvetica"         "NimbusSanCond"        "CenturySch"          
[19] "URWPalladio"          "NimbusRom"            "URWTimes"            
[22] "URW2Helvetica"        "URW2HelveticaItalic"  "URW2Times"           
[25] "NimbusMonoPS"         "ArialMT"              "ComputerModern"      
[28] "ComputerModernItalic" "Japan1"               "Japan1HeiMin"        
[31] "Japan1GothicBBB"      "Japan1Ryumin"         "Korea1"              
[34] "Korea1deb"            "CNS1"                 "GB1"                 
disease_democ_chart <-ggplot(disease_democ, aes(x = infect_rate, y = democ_score)) + 

labs(x="Infectious Disease Prevalence Score",  y="Democratization Score",title="Comparison of Disease Prevalence and Democratization Score") +
theme_minimal(base_family = "serif")


disease_democ_chart


The alpha number lets us see when the data is overlapping

disease_democ_chart + geom_point(size = 3, alpha = 0.5) + geom_smooth(method = lm, se=FALSE, color = "red")
`geom_smooth()` using formula = 'y ~ x'

library(plotly)

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
p<-disease_democ_chart +

geom_point(size = 2.5, alpha = 0.5) +

geom_smooth(method = lm, se=FALSE, color = "red")


p <- ggplotly(p)
`geom_smooth()` using formula = 'y ~ x'
p
library(gganimate)
No renderer backend detected. gganimate will default to writing frames to separate files
Consider installing:
- the `gifski` package for gif output
- the `av` package for video output
and restarting the R session
library(gapminder)

# Create a basic scatter plot
p <- ggplot(gapminder, aes(gdpPercap, lifeExp,
                           size = pop, 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"
  )

anim <- p +
  transition_time(year) +
  ease_aes("linear")

anim
Warning: No renderer available. Please install the gifski, av, or magick package to
create animated output
NULL