library(gapminder)
library(ggplot2)
year_2007 <- gapminder[gapminder$year == 2007, ]
year_2007
## # A tibble: 142 × 6
##    country     continent  year lifeExp       pop gdpPercap
##    <fct>       <fct>     <int>   <dbl>     <int>     <dbl>
##  1 Afghanistan Asia       2007    43.8  31889923      975.
##  2 Albania     Europe     2007    76.4   3600523     5937.
##  3 Algeria     Africa     2007    72.3  33333216     6223.
##  4 Angola      Africa     2007    42.7  12420476     4797.
##  5 Argentina   Americas   2007    75.3  40301927    12779.
##  6 Australia   Oceania    2007    81.2  20434176    34435.
##  7 Austria     Europe     2007    79.8   8199783    36126.
##  8 Bahrain     Asia       2007    75.6    708573    29796.
##  9 Bangladesh  Asia       2007    64.1 150448339     1391.
## 10 Belgium     Europe     2007    79.4  10392226    33693.
## # ℹ 132 more rows
ggplot(year_2007, aes(x = gdpPercap, y = lifeExp, size = pop, fill = continent, )) +
   geom_point(shape = 21, alpha = 0.5) +
  guides(size = "none", alpha = "none") +
  scale_x_continuous(breaks = c(250,500, 1000, 2000, 4000, 8000, 16000, 32000, 64000, 128000), labels = c("250","500", "1000", "2000", "4000", "8000", "16k", "32k", "64k", "128k"),
                      trans = "log10",
                     limits = c(250, 130000)) +
  scale_y_continuous(breaks = c (10, 20, 30 ,40, 50, 60, 70, 80, 90),
                      limits = c(10, 95)) +
  scale_fill_manual(breaks = c("Africa", "Americas", "Asia", "Europe", "Oceania"), values = c("#4FFFE1", "#4DF75E", "#F91975","#F7F24D","brown"  )) +
  theme_minimal() +
  theme(
    panel.background = element_rect(),
    axis.line = element_line(color = "black"),
    panel.grid.major = element_line(color = "grey"),
    text = element_text(size = 11),
    legend.position = "right") +
  scale_size(range = c(1, 20)
  ) +
  annotate( 
    geom = "text",
    x = 8000, y = 40,
    label = "2007",
    color = "black",
    size = 45,
    alpha = 0.2
    ) +
  labs(
    title = "Gapminder Visualization (2007)",
    subtitle = "Life Expectancy vs. GDP per Capita",
    caption = "Source: Gapminder",
    x = "Income",
    y = "Life Expectancy"
  )