scale_y_continuous(formatter="percent") broken? in v.0.9.0

4,709 views
Skip to first unread message

Gary M

unread,
Mar 7, 2012, 7:21:10 PM3/7/12
to ggplot2
# Something like this does not work in v.0.9.0...(and it should,
right?):

df <- data.frame(a=c("A", "B"), b=rnorm(n=20, mean=.5, sd=.01))
qplot(x=a, y=b, data=df) + scale_y_continuous(formatter="percent")

# or

qplot(x=c("A", "B"), y=c(".5", ".7")) +
scale_y_continuous(formatter="percent")

# error msg:
# Error in continuous_scale(c("y", "ymin", "ymax", "yend",
"yintercept", :
# unused argument(s) (formatter = "percent")

# Help.

Dennis Murphy

unread,
Mar 7, 2012, 7:51:49 PM3/7/12
to Gary M, ggplot2
Hi:

On Wed, Mar 7, 2012 at 4:21 PM, Gary M <garyr...@gmail.com> wrote:
> # Something like this does not work in v.0.9.0...(and it should,
> right?):

Nope, it's changed.


>
> df <- data.frame(a=c("A", "B"), b=rnorm(n=20, mean=.5, sd=.01))
> qplot(x=a, y=b, data=df) + scale_y_continuous(formatter="percent")

Try this:

library('scales')
qplot(x=a, y=b, data=df) + scale_y_continuous(labels=percent)

More details in the ggplot2-0.9.0 transition guide (e.g., see section
7, and in particular, the bottom of p. 31 for an example).

http://bit.ly/AhLHuV

Dennis


>
> # or
>
> qplot(x=c("A", "B"), y=c(".5", ".7")) +
> scale_y_continuous(formatter="percent")
>
> # error msg:
> # Error in continuous_scale(c("y", "ymin", "ymax", "yend",
> "yintercept",  :
> # unused argument(s) (formatter = "percent")
>
> # Help.
>

> --
> 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

Dave Auty

unread,
Mar 8, 2012, 5:26:26 PM3/8/12
to ggplot2
I am having trouble with the labels argument too. In a faceted plot
with scales="free" used, one y-axis has standard number notation and
the other displays scientific notation. I would like to coerce them
both to scientific notation if possible. Is there any way I can do
this in the new version of ggplot2?

ggplot(aes(y = Conc, x = Treatment, linetype = Mineral,
group=Mineral), data = ash2) +
geom_line(aes(y = Conc, x = Treatment, linetype = Mineral,
group=Mineral), position=pd, size=0.7, data=ash2) +
geom_point(aes(y = Conc, x= Treatment, shape= Mineral,
group=Mineral), position=pd, size=2.5, data=ash2) +
facet_grid(Material ~Species+Type, scales="free") +
xlab("Treatment") +
ylab("Concentration (ppm)") +

The same code but with scales="fixed" and the following line added:

+ scale_y_continuous(limits=c(0, 350000), breaks=c(50000, 100000,
150000, 200000, 250000, 300000, 350000), labels=scientific))

throws up the error:

Error in is.vector(labels) : object 'scientific' not found

Ideally I would like to use scales="free" AND have the same notation
on each y-axis. Is there any way to do this?

Thanks,

Dave A

On Mar 7, 7:51 pm, Dennis Murphy <djmu...@gmail.com> wrote:
> Hi:
>

Dennis Murphy

unread,
Mar 8, 2012, 9:40:09 PM3/8/12
to Dave Auty, ggplot2
In the absence of a reproducible example, I'd try loading the scales
package before running your code just in case.

Dennis

Dave Auty

unread,
Mar 9, 2012, 6:20:11 AM3/9/12
to Dennis Murphy, ggplot2
Thanks Dennis, that worked perfectly. 

Dave
Reply all
Reply to author
Forward
0 new messages