change x-axis ticks and labels

2,937 views
Skip to first unread message

thomas

unread,
Aug 1, 2010, 7:45:03 PM8/1/10
to ggplot2
Hi,

I was trying to change the ticks on the x-axis to custom labels and
the width of each tick should be set depending on the dataset.

my dataset looks like this:
ID, Name, samplesize,group
0,B61,8,B
1,G12,1,G
2,B32,38,B
goes on like this for a few 100 lines ;)

and i tried this:

Now i have no ticks/labels at all. I would like the ticks to be where
the group 'ends'. The chart gets sorted by Name, so the group is
sorted as well (since it is the first character of the Name). But
somehow with the above I have no ticks at all.

And the second thing I couldn't solve: how can I get the labels
between the ticks? Since the group spans over several subgroups, it
would make way more sense to have the label of the x-axis between the
ticks.

I can't seem to be able to add a file, so I uploaded to imageshack:

Any tips and recommendations appreciated, I am new to both R and
ggplot2 ;)


Thanks,
Thomas

thomas

unread,
Aug 1, 2010, 7:47:03 PM8/1/10
to ggplot2
Hi,

I was trying to change the ticks on the x-axis to custom labels and
the width of each tick should be set depending on the dataset.

my dataset looks like this:
ID, Name, samplesize,group
0,B61,8,B
1,G12,1,G
2,B32,38,B
goes on like this for a few 100 lines ;)

and i tried this:
qplot(ID, samplesize, data=data, geom="line") +
opts(legend.position="none") + xlab("Class") + ylab("Sample Size") +
scale_x_discrete(labels=c("A","B","C","D","E","F","G","H"),breaks=c(10,20,30,40,50,60,70,80))

Now i have no ticks/labels at all. I would like the ticks to be where
the group 'ends'. The chart gets sorted by Name, so the group is
sorted as well (since it is the first character of the Name). But
somehow with the above I have no ticks at all.

And the second thing I couldn't solve: how can I get the labels
between the ticks? Since the group spans over several subgroups, it
would make way more sense to have the label of the x-axis between the
ticks.

I can't seem to be able to add a file, so I uploaded to imageshack:
http://tinyurl.com/39yzbhf

Any tips and recommendations appreciated, I am new to both R and
ggplot2 ;)

Thanks,
Thomas

ps: apologies for my previous posts, google rejected my post

thomas

unread,
Aug 1, 2010, 8:05:47 PM8/1/10
to ggplot2
Hi,

ok, one should chose the correct function, scale_x_continuous() it is.
How I position the labels in between the ticks I still don't know.

Best,
Thomas

Hadley Wickham

unread,
Aug 2, 2010, 5:20:56 PM8/2/10
to thomas, ggplot2
> How I position the labels in between the ticks I still don't know.

That's not possible with ggplot2.

Hadley


--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

thomas

unread,
Aug 2, 2010, 7:33:21 PM8/2/10
to ggplot2
and I guess it isn't coming any time soon either?

Thomas

Hadley Wickham

unread,
Aug 2, 2010, 7:44:39 PM8/2/10
to thomas, ggplot2
It's currently not planned. I'm not sure I understand the point of
labelling the gaps.
Hadley

> --
> You received this message because you are subscribed to the ggplot2 mailing list.
> Please provide a reproducible example: http://gist.github.com/270442
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2

thomas

unread,
Aug 2, 2010, 8:12:53 PM8/2/10
to ggplot2
If my x-axis has 1500 data points that come from 1500 different
categories, I might not want to show all 1500 of them.
If the categories are in a hierarchical system, I rather go up one or
two levels and show only 10 categories. But now the 10 categories span
more than a single tick. And by putting the label not under the tick
but between two ticks, I can make that happen.
Isn't this pretty common?

Thomas

Hadley Wickham

unread,
Aug 9, 2010, 11:05:52 PM8/9/10
to thomas, ggplot2
It's obviously not the common, because no one else has needed it
before ;) I think the best way to handle this would be with
facetting, but there are some bugs and limitations that currently make
it impossible. I'm working on those at the moment, and will hopefully
have improvements within the next two weeks.

Hadley

thomas

unread,
Aug 10, 2010, 6:39:26 AM8/10/10
to ggplot2
yes, facetting (a facet_grid (1 row, 8 columns)) would probably be
possible too. but they do add visual overhead.

Thomas
Reply all
Reply to author
Forward
0 new messages