top of page

Visualizing associations among quantitative variables : Scatter plots


library(ggplot2)

ggplot(df, aes(Mass, Head)) + 
  geom_point(pch = 21, 
             fill = "gray25", 
             color = "white", size = 5) +
  scale_x_continuous(name = "Body mass (g)") +
  scale_y_continuous(name = "Head length (mm)") 






ggplot(df, 
       aes(Mass, Head, fill = KnownSex)) + 
  geom_point(pch = 21, color = "white", size = 5) +
  scale_x_continuous(name = "Body mass (g)") +
  scale_y_continuous(name = "Head length (mm)") +
  scale_fill_manual(values = c(F = "blue", M = "red"),
                    breaks = c("F", "M"),
                    labels = c("female birds   ", "male birds"),
                    name = NULL,
                    guide = guide_legend(direction = "horizontal",
                                         override.aes = list(size = 5))) +
  theme(legend.position = "bottom",
        legend.justification = "right",
        legend.box.spacing = unit(3.5, "pt"), # distance between legend and plot
        legend.text = element_text(vjust = 0.6),
        legend.spacing.x = unit(2, "pt"),
        legend.background = element_rect(fill = "white", color = NA),
        legend.key.width = unit(10, "pt"))


















Comments


bottom of page