This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.

Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Ctrl+Shift+Enter.

library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.5.1     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.1
## ✔ purrr     1.0.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(ggplot2)

capacity <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2022/2022-05-03/capacity.csv')
## Rows: 49 Columns: 7
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (1): type
## dbl (6): year, standalone_prior, hybrid_prior, standalone_new, hybrid_new, t...
## 
## ℹ 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.
g <- ggplot(data=capacity %>% filter(type == "Solar")) + geom_line(aes(x=year,y=total_gw))
print(g)

g <- ggplot(data=capacity %>% filter(type == "Solar")) + geom_line(aes(x=year,y=total_gw)) + geom_point(aes(x=year,y=total_gw))
print(g)

g <- ggplot() + 
  geom_line(data=capacity %>% filter(type=="Solar"),aes(x=year,y=total_gw), color="red") + 
  geom_line(data=capacity %>% filter(type=="Wind"),aes(x=year,y=total_gw), color="blue")
print(g)

g <- 
  ggplot(   data=capacity %>% filter(  type %in% c("Solar","Wind","Storage")  ))  + 
  geom_line(   aes(x=year,  y=total_gw,  color=type)  )
print(g)

g <- ggplot(data=capacity) + geom_line(aes(x=year,y=total_gw,color=type))
print(g)

g <- ggplot() + 
  geom_line(data=capacity %>% filter(type == "Solar"), aes(x=year,y=total_gw,color=type)) +
  geom_line(data=capacity %>% filter(type == "Wind"), aes(x=year,y=total_gw,color=type)) +
  geom_line(data=capacity %>% filter(type == "Storage"),aes(x=year,y=total_gw,color=type)) 
print(g)

g <- 
  #Data
  ggplot(data=capacity %>% filter(type %in% c("Solar","Wind","Storage"))) + 
  
  # Graph and Aesthetics
  geom_line(aes(x=year,y=total_gw,color=type),size=1.5) +
  
  # Labels 
  ylab("Total Gigawatts") + # Y-axis label
  xlab("Year") + # X-axis label
  labs(color = "Energy Type") + # Legend label (if necessary)
  
  # Scales and limits
  scale_x_continuous(breaks = seq(2014,2020, by=1)) + # X axis 
  scale_y_continuous(limits = c(0,500)) + # Y axis
  
  # Theme
  theme_minimal()+
  theme(plot.title=element_text(size = 16, face = "bold"), #Title Font and Size
        axis.text=element_text(size=12), #Axis Label Font and Size
        axis.title=element_text(size=14,face="bold"))+ #Axis Title Font and Size
  
  # Title
  ggtitle("Growth of Renewable Energy Sources") 
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
print(g)

ggsave("output/growth-little.png",width=1500,height=1500, units = "px")
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
ggplotly(g)