highlight a small set of points among a much larger set

736 views
Skip to first unread message

Juliet Hannah

unread,
Feb 17, 2011, 11:36:00 AM2/17/11
to ggplot2
Hey Group,

I am trying to plot two sets of points using two colors. The second
set is much smaller than the first set, so when I plot them, we cannot
really see the second set among all the points. Here is an example

library("ggplot2")
N1 <- 10000
N2 <- 10
myData1 <- data.frame(x=
rnorm(N1,6,3),y=runif(N1),condition=rep("treatment",N1))
myData2 <- data.frame(x= rnorm(N2,6,3),y=runif(N2),condition=rep("control",N2))
allData <- rbind(myData1,myData2)

library(ggplot2)
p <- ggplot(allData,aes(x=x,y=y,colour=factor(condition)))
p <- p + geom_point()
p

To work around this, I used layers. But then I lose the legend
indicating what the color corresponds to.

library(ggplot2)
p <- ggplot(myData1,aes(x=x,y=y))
p <- p + geom_point(alpha=0.1)
p <- p + layer(data=myData2,mapping=aes(x=x,y=y),geom='point',colour='red')
p

Any suggestions on how to improve my plot. Thanks!

Juliet

Brandon Hurr

unread,
Feb 17, 2011, 1:27:48 PM2/17/11
to Juliet Hannah, ggplot2
How about using scale size and manually defining the color? 

#adjusting size
library(ggplot2)
p <- ggplot(allData,aes(x=x,y=y,colour=factor(condition), size=factor(condition)))
p <-  p + geom_point()
p

#adding manual color
p+ scale_colour_manual(values = c("pink", "black"))


Brandon



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

Ben Bolker

unread,
Feb 17, 2011, 1:31:36 PM2/17/11
to Brandon Hurr, ggplot2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


This works, more or less ... although I think it's a bit of an
accident. Couldn't figure out the equivalent of scale_alpha_manual,
although I guess one could hack up a way to use scale_alpha_identity ...

ggplot(allData,aes(x=x,y=y,colour=factor(condition),
alpha=as.numeric(condition)))+
geom_point()+
scale_alpha_continuous(legend=FALSE)+
scale_colour_manual(value=c("black","red"))

> <mailto:ggp...@googlegroups.com>
> To unsubscribe: email ggplot2+u...@googlegroups.com
> <mailto:ggplot2%2Bunsu...@googlegroups.com>
> More options: http://groups.google.com/group/ggplot2


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

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk1daYgACgkQc5UpGjwzenOhugCfVVxH5YmfsT5pNAcEyEmkpIT2
QQwAn2ZUViZITbaxcikl85KKVIqxHy9E
=xzxq
-----END PGP SIGNATURE-----

Brandon Hurr

unread,
Feb 17, 2011, 1:51:51 PM2/17/11
to Ben Bolker, ggplot2
Ooooooh, that is nice. 

Adam_L...@keybank.com

unread,
Feb 17, 2011, 3:09:48 PM2/17/11
to ggplot2

Is it possible (and easy) to extract the names of the colors used in a plot by default, so that one can use the appropriate color when manually adding to the plot?



Adam Loveland



Email Classification: KeyCorp Internal


This communication may contain privileged and/or confidential information. It
is intended solely for the use of the addressee. If you are not the intended
recipient, you are strictly prohibited from disclosing, copying, distributing
or using any of this information. If you received this communication in error,
please contact the sender immediately and destroy the material in its entirety,
whether electronic or hard copy. This communication may contain nonpublic personal
information about consumers subject to the restrictions of the 
Gramm-Leach-Bliley Act. You may not directly or indirectly reuse or redisclose
such information for any purpose other than to provide the services for which
you are receiving the information.

127 Public Square, Cleveland, OH 44114



If you prefer not to receive future e-mail offers for products or services from Key
send an e-mail to mailto:DNERe...@key.com with 'No Promotional E-mails' in the
SUBJECT line.

McCreight

unread,
Feb 17, 2011, 3:35:42 PM2/17/11
to ggplot2
in response to Adam,

not that I know of, but someone might say otherwise.

another, relatively easy, option is to go to the source code for the
palettes as baptiste sugested here

http://groups.google.com/group/ggplot2/browse_thread/thread/15cd90e165573a24/9ff82794823c84dd?

for scale_hue

https://github.com/hadley/scales/raw/master/R/pal-hue.r

it requires a bit of advance planning, but not much. Other palettes
are listed

https://github.com/hadley/scales/tree/master/R

James

On Feb 17, 1:09 pm, Adam_Lovel...@KeyBank.com wrote:
> Is it possible (and easy) to extract the names of the colors used in a
> plot by default, so that one can use the appropriate color when manually
> adding to the plot?
>
> Adam Loveland
>
> Email Classification: KeyCorp Internal
> </pre>
>
> This communication may contain privileged and/or confidential information. It
> is intended solely for the use of the addressee. If you are not the intended
> recipient, you are strictly prohibited from disclosing, copying, distributing
> or using any of this information. If you received this communication in error,
> please contact the sender immediately and destroy the material in its entirety,
> whether electronic or hard copy. This communication may contain nonpublic personal
> information about consumers subject to the restrictions of the
> Gramm-Leach-Bliley Act. You may not directly or indirectly reuse or redisclose
> such information for any purpose other than to provide the services for which
> you are receiving the information.
>
> 127 Public Square, Cleveland, OH 44114
>
> <pre>
>
> If you prefer not to receive future e-mail offers for products or services from Key
> send an e-mail to mailto:DNEReque...@key.com with 'No Promotional E-mails' in the
> SUBJECT line.

Adam_L...@keybank.com

unread,
Feb 17, 2011, 4:25:53 PM2/17/11
to McCreight, ggplot2

Thanks very much! That did the trick.

One more quick question - is there a function that translates between hexadecimal representations of colors and the english names?

Thanks again.



Adam Loveland




McCreight <mccr...@gmail.com>
Sent by: ggp...@googlegroups.com

02/17/2011 03:35 PM

To
ggplot2 <ggp...@googlegroups.com>
cc
Subject
Re: extract colors used in plot





Ben Bolker

unread,
Feb 17, 2011, 4:32:02 PM2/17/11
to Adam_L...@keybank.com, McCreight, ggplot2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 02/17/2011 04:25 PM, Adam_L...@KeyBank.com wrote:
>
> Thanks very much! That did the trick.
>
> One more quick question - is there a function that translates between
> hexadecimal representations of colors and the english names?
>

plotrix::color.id


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk1dk9IACgkQc5UpGjwzenPWbgCfcAIvwWIZFBb9DnA+UZrldtHu
Hb8An0jJ14IoqDH6hthSmNkwUt17tnMd
=lQAo
-----END PGP SIGNATURE-----

Reply all
Reply to author
Forward
0 new messages