Graphics Reference
In-Depth Information
function
(x) exp(x)),
labels
=
trans_format(
"log"
, math_format(e
^
.
x)))
+
scale_y_continuous(trans
=
log2_trans(),
breaks
=
trans_breaks(
"log2"
,
function
breaks
=
trans_breaks(
"log"
,
function
function
(x)
2
^
x),
labels
=
trans_format(
"log2"
, math_format(
2
^
.
x)))
It's possible to use a log axis for just one axis. It is often useful to represent financial data this
way, because it better represents proportional change.
Figure 8-30
shows Apple's stock price
with linear and log y-axes. The default tick marks might not be spaced well for your graph; they
can be set with the
breaks
in the scale:
library(gcookbook)
# For the data set
ggplot(aapl, aes(x
=
date,y
=
adj_price))
+
geom_line()
ggplot(aapl, aes(x
=
date,y
=
adj_price))
+
geom_line()
+
scale_y_log10(breaks
=
c(
2
,
10
,
50
,
250
))