StatisticsNZ / simplevis

Simple visualisation with ggplot2 and leaflet wrappers
https://StatisticsNZ.github.io/simplevis
Other
86 stars 11 forks source link

col_legend: add col_legend_bottom arg #436

Closed davidhodge931 closed 2 years ago

davidhodge931 commented 2 years ago

col_legend_place = c("right", "botttom", "top") col_legend_ncol = NULL

Or just.. col_legend_bottom = TRUE

library(simplevis)
library(tidyverse)

iris %>%
  gg_point_col(
    x_var = Sepal.Width,
    y_var = Sepal.Length,
    col_var = Species,
    title = "Fisher's iris dataset",
    subtitle = "Sepal length by sepal width and species",
    caption = "Source: Fisher, 1936"
  )

iris %>%
  gg_point_col(
    x_var = Sepal.Width,
    y_var = Sepal.Length,
    col_var = Species,
    title = "Fisher's iris dataset",
    subtitle = "Sepal length by sepal width and petal width",
    caption = "Source: Fisher, 1936" 
  ) +
  theme(legend.position = "bottom") +
  theme(legend.direction = "horizontal") +
  guides(col = guide_legend(title.position = "top")) +
  theme(legend.title = element_text(vjust = 0.25)) 

iris %>%
  gg_point_col(
    x_var = Sepal.Width,
    y_var = Sepal.Length,
    col_var = Petal.Width,
    title = "Fisher's iris dataset",
    subtitle = "Sepal length by sepal width and petal width",
    caption = "Source: Fisher, 1936", 
    col_breaks_n = 2
  )

iris %>%
  gg_point_col(
    x_var = Sepal.Width,
    y_var = Sepal.Length,
    col_var = Petal.Width,
    title = "Fisher's iris dataset",
    subtitle = "Sepal length by sepal width and petal width",
    caption = "Source: Fisher, 1936", 
    col_breaks_n = 2
  ) +
  theme(legend.position = "bottom") +
  theme(legend.direction = "horizontal") +
  guides(col = guide_colorbar(title.position = "top"))

iris %>%
  gg_point_col(
    x_var = Sepal.Width,
    y_var = Sepal.Length,
    col_var = Petal.Width,
    title = "Fisher's iris dataset",
    subtitle = "Sepal length by sepal width and petal width",
    caption = "Source: Fisher, 1936", 
    col_method = "bin", 
  )

iris %>%
  gg_point_col(
    x_var = Sepal.Width,
    y_var = Sepal.Length,
    col_var = Petal.Width,
    title = "Fisher's iris dataset",
    subtitle = "Sepal length by sepal width and petal width",
    caption = "Source: Fisher, 1936", 
    col_method = "bin", 
  ) +
  theme(legend.position = "bottom") +
  theme(legend.direction = "horizontal") +
  guides(col = guide_legend(reverse = FALSE, title.position = "top")) +
  theme(axis.title.x = element_text(margin = margin(t = 5))) +
  theme(axis.title.y = element_text(margin = margin(r = 10)))

iris %>%
  gg_point_facet(
    x_var = Sepal.Width,
    y_var = Sepal.Length,
    facet_var = Species,
    title = "Fisher's iris dataset",
    subtitle = "Sepal length by sepal width and species",
    caption = "Source: Fisher, 1936"
  )

iris %>%
  gg_point_col_facet(
    x_var = Sepal.Width,
    y_var = Sepal.Length,
    col_var = Species,
    facet_var = Species,
    title = "Fisher's iris dataset",
    subtitle = "Sepal length by sepal width and species",
    # col_title = ggplot2::waiver(),
    caption = "Source: Fisher"
  ) +
  theme(legend.position = "bottom") +
  theme(legend.direction = "horizontal") +
  guides(col = guide_legend(title.position = "top")) +
  theme(legend.title = element_text(vjust = 0.25)) 
davidhodge931 commented 2 years ago

Only use legend position on top for bottom/top, if col_title does not equal ""

davidhodge931 commented 2 years ago

library(simplevis) library(tidyverse)

iris %>% gg_point_col( x_var = Sepal.Width, y_var = Sepal.Length, col_var = Species, title = "Fisher's iris dataset", subtitle = "Sepal length by sepal width and species", caption = "Source: Fisher, 1936", col_legend_position = "bottom", col_legend_ncol = NULL, col_legend_nrow = NULL )

davidhodge931 commented 2 years ago

Should be col_legend_place if I was to do this like ggblanket. But can't be bothered