geom_point in terms of two 'size' variables

38 views
Skip to first unread message

Mikołaj Bogucki

unread,
Aug 27, 2015, 12:34:00 PM8/27/15
to ggplot2

Hi, Is there any option to use two variables in parameter size in ggplot function? E.g.

ggplot(mtcars, aes(qsec,drat, size = cyl))+
geom_point()

Obviously it works and size of points depends on cyl variable. But is it any option to add another sizevariable which can use alpha option e.g.variable = mpg. I found sth like that:

ggplot() +
geom_point(data = mtcars, aes(qsec,drat, size = cyl)) +
geom_point(data = mtcars, aes(qsec,drat, size = mpg), alpha = .1, colour = "red")

But when I want to set the size of each variable separately, it is not possible. When there is one size variable normally I use scale_size_contiunous but with two size variables it doesn't work. I know that using scale_size_continuous two times doesn't change anything. It is possible to achieve appropriate graph?

Brandon Hurr

unread,
Aug 27, 2015, 1:29:12 PM8/27/15
to Mikołaj Bogucki, ggplot2
My understanding is that only a single scale of each type can be used
in a plot. Much like Highlander, there can only be one.

In your example, it is setting the scale to cover both cyl and mpg.
Your dots are reflecting the data quite well if you ask me. I assume
you want to have the cyl scale and the mpg scale on their own scale so
they show up better. AFAIK, that can't be done. BUT... you could try
rescaling cyl to the mpg scale or vice versa, but then your legend is
kind of junk.

HTH,
B
> --
> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example:
> https://github.com/hadley/devtools/wiki/Reproducibility
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ggplot2" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ggplot2+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages