how to adjust the distance between x ticks

3,117 views
Skip to first unread message

Li Xue

unread,
Nov 28, 2009, 11:38:12 AM11/28/09
to ggp...@googlegroups.com
Hello,

The labels of x ticks in my plot is too long and they overlapped. How can I make the distance between x ticks larger?

Thanks,

Li

David Kahle

unread,
Nov 28, 2009, 12:05:14 PM11/28/09
to Li Xue, ggp...@googlegroups.com
Check out the breaks argument in scale_x_continuous, e.g.

qplot(1:10, 1:10)
qplot(1:10, 1:10) + scale_x_continuous(breaks = c(1,5,10))

Cheers
david.

--
You received this message because you are subscribed to the ggplot2 mailing list.
To post to this group, send email to ggp...@googlegroups.com
To unsubscribe from this group, send email to
ggplot2+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/ggplot2

Li Xue

unread,
Nov 28, 2009, 9:51:00 PM11/28/09
to David Kahle, ggp...@googlegroups.com
Hey David,

Thank you for your prompt reply.

Is there anyway that I can still show all x-ticks and just make the interval between x-ticks larger?

Thanks a lot,

Li
--
Xue, Li
Bioinformatics and Computational Biology program
Computer Science
Iowa State University
Ames, IA 50010 - USA
Tel: 1-515-450-7183
Email: me.l...@gmail.com

David Kahle

unread,
Nov 28, 2009, 10:03:26 PM11/28/09
to Li Xue, ggp...@googlegroups.com
You can enlarge the viewing window (either when you are viewing or saving, see ggsave() and enlarge the width).

Otherwise, if you are having a hard time reading them, say, if they overlap for example, you can try something like

labs <- paste('Sample text', 1:10)
qplot(factor(1:10), 1:10) + 
  scale_x_discrete(labels = labs) +
  opts(axis.text.x
    theme_text(angle = 30, size = 8, vjust = 2, hjust = .75))

Hope it helps
david.

Li Xue

unread,
Nov 28, 2009, 10:32:48 PM11/28/09
to David Kahle, ggp...@googlegroups.com
Hey David,

Thanks a lot. This is exactly what I want.

Li
Reply all
Reply to author
Forward
0 new messages