https://github.com/ben-williams/tickr
Making consistent tick marks for R plots
https://github.com/ben-williams/tickr
axis-labels ggplot2 ticks
Last synced: 25 days ago
JSON representation
Making consistent tick marks for R plots
- Host: GitHub
- URL: https://github.com/ben-williams/tickr
- Owner: ben-williams
- License: other
- Created: 2025-04-07T21:04:08.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2025-04-10T16:01:09.000Z (7 months ago)
- Last Synced: 2025-10-12T15:58:05.857Z (about 1 month ago)
- Topics: axis-labels, ggplot2, ticks
- Language: R
- Homepage:
- Size: 56.6 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE
Awesome Lists containing this project
- awesome-ggplot2 - tickr
README
---
output: github_document
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# tickr

This is a small package to provide consistent tick marks for plotting `ggplot2` figures.
It provides breaks and labels for ggplot2 without requiring ggplot2 to be installed.
## Installation
You can install the development version of `tickr` from GitHub:
``` r
# install.packages("remotes")
remotes::install_github("BenWilliams-NOAA/tickr")
```
## Example
```{r setup}
library(tickr)
library(ggplot2)
library(dplyr)
```
Some basic examples of how to use the `tickr` package.
```{r}
# Create a data.frame
df <- data.frame(year = 2000:2020,
spawning_biomass = rnorm(21,100, 0.25))
# explore tickr output
tickr(df, var=year)
tickr(df, var=year, by=2)
tickr(df, var=year, by=5, var_min = 1998, var_max = 2024, lab_start = 1998, lab_end = 2017)
tickr(df, var=year, by=5, var_min = 1998, var_max = 2024, lab_start = 1998, lab_end = 2017)
# explore plotting options
# default ggplot
ggplot(df, aes(year, spawning_biomass)) +
geom_line() +
geom_point()
# a tick mark for every year
ggplot(df, aes(year, spawning_biomass)) +
geom_line() +
geom_point() +
scale_x_tickr(data=df, var=year)
# a tick mark for every year & label every 2nd year
ggplot(df, aes(year, spawning_biomass)) +
geom_line() +
geom_point() +
scale_x_tickr(data=df, var=year, by = 2)
# determine the years that are labeled
ggplot(df, aes(year, spawning_biomass)) +
geom_line() +
geom_point() +
scale_x_tickr(data=df, var=year, by = 5,
var_min = 1997,
var_max = 2024,
lab_start = 1997)
# determine the years that are labeled
ggplot(df, aes(year, spawning_biomass)) +
geom_line() +
geom_point() +
scale_x_tickr(data=df, var=year, by = 2,
var_min = 2010,
lab_start = 2010)
# show future years
ggplot(df, aes(year, spawning_biomass)) +
geom_line() +
geom_point() +
scale_x_tickr(data=df, var=year, by = 5,
var_min = 2015,
var_max = 2026,
lab_start = 2015,
lab_end = 2026) +
expand_limits(x = c(1998, 2026))
```
The same general approach is available for y axes as well.
```{r}
df <- expand.grid(age = 1:10,
year = 2000:2009) %>%
dplyr::mutate(value = rnorm(100, 1, 1))
df %>%
ggplot(aes(year, age, size=value)) +
geom_point() +
scale_size_area() +
scale_x_tickr(data=df, var=year, by=2, var_max = 2012, lab_end = 2012) +
scale_y_tickr(data=df, var=age, by=2) +
expand_limits(y=0, x=2012)
```