scale_alpha_identity

76 views
Skip to first unread message

David Kahle

unread,
Sep 30, 2010, 5:05:43 PM9/30/10
to ggplot2
Hi all -

I want to manually provide the values for the alpha value.  See the following example for details.

df <- data.frame(
  x = 1:10,
  y = 1:10,
  alpha = (1:10) / 20
)

# notice that the alpha variable is being scaled as it should be
ggplot(aes(x = x, y = y, alpha = alpha), data = df) +
  geom_point()

  

  

# however if we don't want the scaling, we can't code it in the usual way
# (i.e., the function doesn't exist)
ggplot(aes(x = x, y = y, alpha = alpha), data = df) +
  geom_point() +
  scale_alpha_identity()

Is there a reason why the scale_identity function isn't included for the alpha aesthetic, or am I missing something?

Cheers
david.

----------------------------------
----------------------------------
David Kahle 
Rice University 
Rm. 1041 Duncan Hall 
Department of Statistics, MS 138 
6100 Main St. 
Houston, TX 77005

Ista Zahn

unread,
Sep 30, 2010, 5:46:09 PM9/30/10
to David Kahle, ggplot2
Hi David,
Actually I did not know about scale_*_identity. Interesting. Anyway, I
think you can get what you want like this:

ggplot(df, aes(x =x, y = y, alpha=alpha)) +
geom_point() +
scale_alpha(breaks=df$alpha, to = c(0.05, 0.50), legend=FALSE)

Best,
Ista

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

--
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org

David Kahle

unread,
Sep 30, 2010, 6:07:53 PM9/30/10
to Ista Zahn, ggplot2
Hi Ista -

Thanks for a quick response! This actually does work for my intended
purpose, so thanks again.

Unfortunately it doesn't quite capture the scale_identity, does it.
Is there any way to implement that?

Cheers
david.

Ista Zahn

unread,
Sep 30, 2010, 6:25:32 PM9/30/10
to David Kahle, ggplot2
Hi David,

On Thu, Sep 30, 2010 at 6:07 PM, David Kahle <david...@gmail.com> wrote:
> Hi Ista -
>
> Thanks for a quick response!  This actually does work for my intended
> purpose, so thanks again.
>
> Unfortunately it doesn't quite capture the scale_identity, does it.  Is
> there any way to implement that?

Actually it turns out to be easy...

scale_alpha_identity <- function (name = NULL, limits = NULL, breaks =
NULL, labels = NULL, trans = NULL, to = c(0.1, 1), legend = TRUE, ...)
{
ScaleIdentity$new(name = name, breaks = breaks, labels = labels,
legend = legend, variable = "alpha", ...)
}

ggplot(df, aes(x =x, y = y, alpha=alpha)) +
geom_point() +

scale_alpha_identity()

-Ista

Hadley Wickham

unread,
Oct 1, 2010, 9:52:05 AM10/1/10
to David Kahle, ggplot2
This seems to be a simple omission. You can fix it with:

scale_alpha_identity <- function (name = NULL, breaks = NULL, labels =
NULL, formatter = NULL,


legend = TRUE, ...) ScaleIdentity$new(name = name, breaks =
breaks, labels = labels,

formatter = formatter, legend = legend, variable = "alpha", ...)

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
>

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

Reply all
Reply to author
Forward
0 new messages