Day1

news
Author

Arvind v

Published

October 2, 2024

This is the first post in a Quarto blog. Welcome!

Since this post doesn’t specify an explicit image, the first image in the post will be used in the listing page of posts.

Setting up R Packages

library(tidyverse)
library(ggformula)

Our first graph

Let us look at the variable names:

penguins %>% names()
[1] "species"     "island"      "bill_len"    "bill_dep"    "flipper_len"
[6] "body_mass"   "sex"         "year"       

OK, let’s do a scatter plot: this chart should be automatically formatted and themed using the ggplot2 theme defined at project root in the file _setup.qmd.

penguins %>% drop_na() %>% 
  gf_point(body_mass ~ flipper_len, colour = ~ species, size = 2) %>% 
  gf_labs(title = "My Penguin Plot", x = "Flipper Length", y = "Body Mass (gms)") %>% 
  gf_refine(annotate(geom = "text", label = "Important\n Points", x = 220, y = 3500, size = 5),
            annotate(geom = "rect", xmin = 200, xmax = 210, ymin = 3000, ymax = 5700, alpha = .2),
            annotate('curve',x = 220, y = 3200,yend = 3000,xend = 205,
    linewidth = 1, curvature = -0.5, arrow = arrow(length = unit(0.5, 'cm')))) %>%
  
  ## Labels and Title
  gf_labs(
    title = 'Bill Dimensions of Brush-Tailed Penguins (Pygoscelis)',
    subtitle = 'A scatter plot of bill depth versus bill length.',
    caption = 'Data: Gorman, Williams & Fraser (2014) PLoS ONE',
    x = 'Bill Length (mm)', 
    y = 'Bill Depth (mm)',
    color = 'Body mass (g)'
  )