Suppressing ticks on x axis only; space between y axis and label

107 views
Skip to first unread message

Nicholas Riley

unread,
Mar 8, 2009, 10:03:05 PM3/8/09
to ggplot2
Hi,

I'm plotting several clusters of bars, with only one x value per
cluster, so I'd like to try to suppress the single tick mark at the
bottom of each cluster. Table 8.1 in the ggplot2 book mentions
'axis.ticks' and 'axis.ticks.y', so I tried 'axis.ticks.x', eventually
discovering this option was removed:

http://github.com/hadley/ggplot2/commit/1fb07117af63fa0e9ab49b2f7eae0363d3a9fad5

Is there another method of affecting the x axis ticks without the y
axis ones?

In the same plot, I have a log2-scale y axis with an axis label. Is it
possible to increase the space (which currently appears to be zero)
between the tick labels and axis label?

Thanks.

hadley wickham

unread,
Mar 9, 2009, 9:46:33 AM3/9/09
to Nicholas Riley, ggplot2
Hi Nicholas,

I'd just set the breaks on the x axis to NA - e.g.

qplot(mpg, wt, data = mtcars) + scale_x_continuous(breaks = NA)
qplot(factor(cyl), wt, data = mtcars) + scale_x_discrete(breaks = NA)

Regards,

Hadley

PS. I've corrected that table in the book to avoid future confusion.
--
http://had.co.nz/

Nicholas Riley

unread,
Mar 9, 2009, 11:07:12 PM3/9/09
to ggplot2
On Mon, Mar 9, 2009 at 8:46 AM, hadley wickham <h.wi...@gmail.com> wrote:
> Hi Nicholas,
>
> I'd just set the breaks on the x axis to NA - e.g.
>
> qplot(mpg, wt, data = mtcars) + scale_x_continuous(breaks = NA)
> qplot(factor(cyl), wt, data = mtcars) + scale_x_discrete(breaks = NA)

Thank you, that works wonderfully. My plot is now:

ggplot(runtimes, aes(x='', fill=variants, y=speedup)) +
geom_hline(yintercept=1, colour='grey50') +
geom_bar(stat='identity', position='dodge') +
opts(axis.title.x=theme_blank()) +
facet_grid(. ~ bench) +
scale_x_discrete(breaks=NA) +
scale_y_log2('Speedup (1.0 = CPython 2.4.1)')

(I also tried with x=NA, but that gave me ticks marked 'NA').

>> In the same plot, I have a log2-scale y axis with an axis label. Is it
>> possible to increase the space (which currently appears to be zero)
>> between the tick labels and axis label?

I'm still having this problem (see attached). I've tried every spacing
parameter I could find, but note how the bottom of the left
parenthesis touches the 2 in 2^-1. Any ideas?

--Nicholas

Picture 3.png

hadley wickham

unread,
Mar 9, 2009, 11:26:02 PM3/9/09
to Nicholas Riley, ggplot2
>>> In the same plot, I have a log2-scale y axis with an axis label. Is it
>>> possible to increase the space (which currently appears to be zero)
>>> between the tick labels and axis label?
>
> I'm still having this problem (see attached). I've tried every spacing
> parameter I could find, but note how the bottom of the left
> parenthesis touches the 2 in 2^-1.  Any ideas?

This is a poor spacing choice which I hope to improve in the next
version. In the meantime, the easiest solution is probably just to
add a new line to the axis label:

scale_y_log2('Speedup (1.0 = CPython 2.4.1)\n')

Hadley

--
http://had.co.nz/

Austin Frank

unread,
Mar 19, 2009, 3:29:46 PM3/19/09
to hadley wickham, ggplot2
Hadley and folks--

I'd like to be able to use scale_y_logit() and
coord_trans(ytrans="invlogit") to construct a plot summarizing some
proportion data. I have two problems:

1) scale_y_logit() fails with the error

Error in plogis(q, location, scale, lower.tail, log.p) : Non-numeric
argument to mathematical function

You can see this with the following code:

--8<---------------cut here---------------start------------->8---
library(boot) # logit()
library(ggplot2)

## load binomial data, compute proportion (disregarding sample size
## for this example)
data(cbpp, package="lme4")
cbpp <- within(cbpp, prop <- incidence/size)

## plot the mean proportion. works.
ggplot(cbpp, aes(x=as.numeric(period), y=prop)) +
stat_summary(fun.y=mean, geom="line")

## plot the logit of the mean proportion by hand. works.
ggplot(cbpp, aes(x=as.numeric(period), y=prop)) +
stat_summary(fun.y=function(y) logit(mean(y)), geom="line")

## use a transformer to get the logit of the mean proportion.
## breaks with error reported above
ggplot(cbpp, aes(x=as.numeric(period), y=prop)) +
stat_summary(fun.y=mean, geom="line") +
scale_y_logit()
--8<---------------cut here---------------end--------------->8---

Also, maybe I've got things backwards here, but why does the transformer
to put things onto the logit scale call plogis? plogis takes values in
the logit space and returns probabilities. qlogis takes probabilities
and returns results in logit space.

qlogis(0) # -Inf, logit space
plogis(0) # 0.5, probability space

For a transformation from probability space into logit space, which is
what I think scale_y_logit() is supposed to do, don't we want qlogis?

2) invlogit isn't defined as a possible transform

At the end of the above plot, I'd ideally like to add something like

+ coord_trans(ytrans="invlogit") # should use plogis?

But that transformer is not in the list in table 6.2 of the book. So,
is it possible to define new transformers? What do they have to look
like?

Thanks for any help,
/au

--
Austin Frank
http://aufrank.net
GPG Public Key (D7398C2F): http://aufrank.net/personal.asc

hadley wickham

unread,
Mar 28, 2009, 9:29:13 PM3/28/09
to Austin Frank, ggplot2
On Thu, Mar 19, 2009 at 2:29 PM, Austin Frank <austin...@gmail.com> wrote:
> Hadley and folks--
>
> I'd like to be able to use scale_y_logit() and
> coord_trans(ytrans="invlogit") to construct a plot summarizing some
> proportion data.  I have two problems:
>
> 1) scale_y_logit() fails with the error
>
>  Error in plogis(q, location, scale, lower.tail, log.p) :  Non-numeric
>  argument to mathematical function

Ooops. Fixed in the development version.

Yes, you're right. Fixed in the development version too.

> For a transformation from probability space into logit space, which is
> what I think scale_y_logit() is supposed to do, don't we want qlogis?
>
> 2) invlogit isn't defined as a possible transform
>
> At the end of the above plot, I'd ideally like to add something like
>
>  + coord_trans(ytrans="invlogit") # should use plogis?

To define your own transformer, call Trans$new. It takes three
arguments: the function, it's inverse, and a function to create
labels. A few examples should give you the idea:

TransLog2 <- Trans$new("log2", "log2", function(x) 2^x, function(x)
bquote(2^.(x)))
TransPow10 <- Trans$new("pow10",function(x) 10^x, "log10", function(x) log10(x))

Does that help?

Hadley

--
http://had.co.nz/

Reply all
Reply to author
Forward
0 new messages