Graphics Reference
In-Depth Information
Figure 8-30. Top: a stock chart with a linear x-axis and log y-axis; bottom: with manual breaks
Adding Ticks for a Logarithmic Axis
Problem
You want to add tick marks with diminishing spacing for a logarithmic axis.
Solution
library(MASS)
# For the data set
library(scales)
# For the trans and format functions
ggplot(Animals, aes(x
=
body, y
=
brain, label
=
rownames(Animals)))
+
geom_text(size
=
3
)
+
annotation_logticks()
+
scale_x_log10(breaks
=
trans_breaks(
"log10"
,
function
function
(x)
10
^
x),
labels
=
trans_format(
"log10"
, math_format(
10
^
.
x)))
+
scale_y_log10(breaks
=
trans_breaks(
"log10"
,
function
function
(x)
10
^
x),
labels
=
trans_format(
"log10"
, math_format(
10
^
.
x)))