File: annotation_logticks.Rd

package info (click to toggle)
r-cran-ggplot2 3.4.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 8,748 kB
  • sloc: sh: 15; makefile: 5
file content (117 lines) | stat: -rw-r--r-- 3,936 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/annotation-logticks.r
\name{annotation_logticks}
\alias{annotation_logticks}
\title{Annotation: log tick marks}
\usage{
annotation_logticks(
  base = 10,
  sides = "bl",
  outside = FALSE,
  scaled = TRUE,
  short = unit(0.1, "cm"),
  mid = unit(0.2, "cm"),
  long = unit(0.3, "cm"),
  colour = "black",
  size = 0.5,
  linetype = 1,
  alpha = 1,
  color = NULL,
  ...
)
}
\arguments{
\item{base}{the base of the log (default 10)}

\item{sides}{a string that controls which sides of the plot the log ticks appear on.
It can be set to a string containing any of \code{"trbl"}, for top, right,
bottom, and left.}

\item{outside}{logical that controls whether to move the log ticks outside
of the plot area. Default is off (\code{FALSE}). You will also need to use
\code{coord_cartesian(clip = "off")}. See examples.}

\item{scaled}{is the data already log-scaled? This should be \code{TRUE}
(default) when the data is already transformed with \code{log10()} or when
using \code{scale_y_log10()}. It should be \code{FALSE} when using
\code{coord_trans(y = "log10")}.}

\item{short}{a \code{\link[grid:unit]{grid::unit()}} object specifying the length of the
short tick marks}

\item{mid}{a \code{\link[grid:unit]{grid::unit()}} object specifying the length of the
middle tick marks. In base 10, these are the "5" ticks.}

\item{long}{a \code{\link[grid:unit]{grid::unit()}} object specifying the length of the
long tick marks. In base 10, these are the "1" (or "10") ticks.}

\item{colour}{Colour of the tick marks.}

\item{size}{Thickness of tick marks, in mm.}

\item{linetype}{Linetype of tick marks (\code{solid}, \code{dashed}, etc.)}

\item{alpha}{The transparency of the tick marks.}

\item{color}{An alias for \code{colour}.}

\item{...}{Other parameters passed on to the layer}
}
\description{
This annotation adds log tick marks with diminishing spacing.
These tick marks probably make sense only for base 10.
}
\examples{
# Make a log-log plot (without log ticks)
a <- ggplot(msleep, aes(bodywt, brainwt)) +
 geom_point(na.rm = TRUE) +
 scale_x_log10(
   breaks = scales::trans_breaks("log10", function(x) 10^x),
   labels = scales::trans_format("log10", scales::math_format(10^.x))
 ) +
 scale_y_log10(
   breaks = scales::trans_breaks("log10", function(x) 10^x),
   labels = scales::trans_format("log10", scales::math_format(10^.x))
 ) +
 theme_bw()

a + annotation_logticks()                # Default: log ticks on bottom and left
a + annotation_logticks(sides = "lr")    # Log ticks for y, on left and right
a + annotation_logticks(sides = "trbl")  # All four sides

a + annotation_logticks(sides = "lr", outside = TRUE) +
 coord_cartesian(clip = "off")  # Ticks outside plot

# Hide the minor grid lines because they don't align with the ticks
a + annotation_logticks(sides = "trbl") + theme(panel.grid.minor = element_blank())

# Another way to get the same results as 'a' above: log-transform the data before
# plotting it. Also hide the minor grid lines.
b <- ggplot(msleep, aes(log10(bodywt), log10(brainwt))) +
 geom_point(na.rm = TRUE) +
 scale_x_continuous(name = "body", labels = scales::math_format(10^.x)) +
 scale_y_continuous(name = "brain", labels = scales::math_format(10^.x)) +
 theme_bw() + theme(panel.grid.minor = element_blank())

b + annotation_logticks()

# Using a coordinate transform requires scaled = FALSE
t <- ggplot(msleep, aes(bodywt, brainwt)) +
  geom_point() +
  coord_trans(x = "log10", y = "log10") +
  theme_bw()
t + annotation_logticks(scaled = FALSE)

# Change the length of the ticks
a + annotation_logticks(
  short = unit(.5,"mm"),
  mid = unit(3,"mm"),
  long = unit(4,"mm")
)
}
\seealso{
\code{\link[=scale_y_continuous]{scale_y_continuous()}}, \code{\link[=scale_y_log10]{scale_y_log10()}} for log scale
transformations.

\code{\link[=coord_trans]{coord_trans()}} for log coordinate transformations.
}