Graphics Reference
In-Depth Information
Removing Tick Marks and Labels
Problem
You want to remove tick marks and labels.
Solution
To remove just the tick labels, as in
Figure 8-14
(left), use
theme(axis.text.y = ele-
ment_blank())
(or do the same for
axis.text.x
). This will work for both continuous and
categorical axes:
p
<-
ggplot(PlantGrowth, aes(x
=
group, y
=
weight))
+
geom_boxplot()
p
+
theme(axis.text.y
=
element_blank())
Figure 8-14. Left: no tick labels on y-axis; middle: no tick marks and no tick labels on y-axis; right:
with breaks=NULL
To remove the tick marks, use
theme(axis.ticks=element_blank())
. This will remove the
tick marks on both axes. (It's not possible to hide the tick marks on just one axis.) In this ex-
ample, we'll hide all tick marks as well as the ytick labels (
Figure 8-14
, center):
p
+
theme(axis.ticks
=
element_blank(), axis.text.y
=
element_blank())
To remove the tick marks, the labels, and the grid lines, set
breaks
to
NULL
(
Figure 8-14
, right):
p
+
scale_y_continuous(breaks
=
NULL
NULL
)
This will work for continuous axes only; if you remove items from a categorical axis using
lim-
its
, as in
Changing the Order of Items on a Categorical Axis
, the data with that value won't be
shown at all.