Can outlier points be colored the same as box fill color?

1,284 views
Skip to first unread message

Minard-Smith, Angela T

unread,
Mar 3, 2017, 9:08:44 AM3/3/17
to ggp...@googlegroups.com

I have been trying to get my outlier point colors to match the fill color of my boxes in a ggplot2 boxplot.  I found the update_geom_defaults function and have used it but now the points match the default color scheme as shown in the plot image:

 

What I want is for the outlines of the boxes to match the fill colors and for the outlier points to also match the fill colors.  So a green box will have green outliers, a blue box will have blue outliers etc..  I have attached an example dataset.  Here is the code I am using:

 

update_geom_defaults("point", list(color = NULL))

ggplot(plotdata, aes(Locus, proportion, color = variable, fill = variable))+

geom_boxplot(width = 0.6)+

scale_fill_manual("Sample", values = c("green", "blue", "red"), labels = c("C", "S", "U"))+

theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = .5), plot.title = element_text(hjust = 0.5))

 

I also tried changing the update_geom_default to:

update_geom_defaults("point", list(color = c("green", "blue", "red")))

but this had no effect on the colors in the plot.

 

Note that in the end I do not need two legends for my plot so if there is also a way to not display the second legend I would like to know how to do that as well.

Thank you,

 

Angela

 

This message is intended only for the use of the individual or entity to which it is addressed, and may contain information that is privileged, confidential and/or otherwise exempt from disclosure under applicable law. If the reader of this message is not the intended recipient or the employee or agent responsible for delivering the message to the intended recipient, any disclosure, dissemination, distribution, copying or other use of this communication or its substance is prohibited. If you have received this communication in error, please return to the sender and delete from your computer system.

 

example-plotdata.xlsx

Thierry Onkelinx

unread,
Mar 3, 2017, 9:39:45 AM3/3/17
to Minard-Smith, Angela T, ggp...@googlegroups.com
Dear Angela,

You need to set scale_colour_manual too.

ggplot(plotdata, aes(Locus, proportion, color = variable, fill = variable))+

geom_boxplot(width = 0.6)+

scale_colour_manual("Sample", values = c("green", "blue", "red"), labels = c("C", "S", "U")) +

scale_fill_manual("Sample", values = c("green", "blue", "red"), labels = c("C", "S", "U")) +

theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = .5), plot.title = element_text(hjust = 0.5))


Best regards,


ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest
team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
Kliniekstraat 25
1070 Anderlecht
Belgium

To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data. ~ Roger Brinner
The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey

--
--
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+unsubscribe@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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Minard-Smith, Angela T

unread,
Mar 3, 2017, 12:54:06 PM3/3/17
to Thierry Onkelinx, ggp...@googlegroups.com

Thierry,

Thank you, your solution works.

Angela

 

From: Thierry Onkelinx [mailto:thierry....@inbo.be]
Sent: Friday, March 03, 2017 9:40 AM
To: Minard-Smith, Angela T <MINARD...@battelle.org>
Cc: ggp...@googlegroups.com
Subject: Re: Can outlier points be colored the same as box fill color?

 

Message received from outside the Battelle network. Carefully examine it before you open any links or attachments.

--

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.

Reply all
Reply to author
Forward
0 new messages