[R] Suppressing the labelling of tick marks on ggplot2

Joshua Wiley jwiley.psych at gmail.com
Sat Jul 9 17:45:18 CEST 2011


Hi Chris,

You can use scale_x_discrete() to manually set the locations of the
ticks (the "breaks" argument) and what they are labeled with (the
"labels" argument).  If you want a third of the the ids (or so) you
could do something like:

breaks = factor(bb.res.math$id.bb)[seq(1, length(bb.res.math$id.bb), by = 3)]

and just change the sequence to skip as many as you want.  Of course,
you can fully customize it and manually pick each and every id if you
really want.

HTH,

Josh

P.S. There is a mailing list specifically for ggplot2 on google groups.

On Sat, Jul 9, 2011 at 7:12 AM, Christopher Desjardins <desja004 at umn.edu> wrote:
> Hi,
> I have the follow ggplot2 code I am running:
>
> ggplot(data=bb.res.math,aes(x=factor(id.bb),y=bb.math.comb,fill=BB)) + geom_bar() + facet_grid(BB~.) + scale_fill_brewer(pal="Set1") + ylab("Average Student Residual (Math)") + xlab("Student ID")
>
> The number of unique id.bb is 2207 and so my X-axis has a couple of thousands, indistinguishable tick marks that correspond to each id. I am wondering if there is a way to suppress these tick marks?
>
> Here is some test data:
>
>> test
>  id.bb bb.res.m bb.math.comb BB
> 1  2900        1   -3.0032235 BB
> 2  2904        1   -1.8758770 BB
> 3  3469        1    0.8182852 BB
> 4  4213        1   -2.0660215 Not BB
> 5  4215        1   -4.8622086 BB
> 6  4395        1    0.8873996 Not BB
>
>> ggplot(data=test,aes(x=factor(id.bb),y=bb.math.comb,fill=BB)) + geom_bar() + facet_grid(BB~.) + scale_fill_brewer(pal="Set1") + ylab("Average Student Residual (Math)") + xlab("Student ID")
>
>
> Gives the following graph:
>
> http://dl.dropbox.com/u/1501309/ggplot2_suppress_ids.pdf
>
> I'd like to prevent "2900", "2904", "3469", etc. from showing up on the X-axis.
>
> Thanks,
> Chris
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
https://joshuawiley.com/



More information about the R-help mailing list