ggplot: customize the color of margins of dotscolors for two geom_point() in ggplot2 when using aes_stringIndividual Points Not Showing Up on Plotly (but do show up in ggplot2)Creating a ggplot legend with color and linetype based on two variablesHow to merge color, line style and shape legends in ggplotAggregating data with ggplotLegends for multiple fills in ggplotCreate annotation for a balloon plot from gplots packagechange color data points plotLearnerPrediction (MLR package)Add legends corresponding to the layers in ggplotChange fill color of dotplot_geom but retain fill color of boxplot

Is it impolite to ask for halal food when traveling to and in Thailand?

Labview vs Matlab??Which one better for image processing?

Averting Bathos

Is it too late to harvest aronia berries

Is differentiation as a map discontinuous?

A file manager to open a zip file like opening a folder, instead of extract it by using a archive manager

My Project Manager does not accept carry-over in Scrum, Is that normal?

Line segments inside a square

Under what circumstances would RAM locations 0 and 1 be written and/or read on the C64?

Why does (inf + 0j)*1 evaluate to inf + nanj?

My manager quit. Should I agree to defer wage increase to accommodate budget concerns?

How can an attacker use robots.txt?

Safe to use 220V electric clothes dryer when building has been bridged down to 110V?

How to say "cheat sheet" in French

Co-supervisor comes to the office to help her students, which distracts me

Is it acceptable to say that a reviewer's concern is not going to be addressed because then the paper would be too long?

Does wetting a beer glass change the foam characteristics?

What benefits does the Power Word Kill spell have?

List of 1000 most common words across all languages

Difference between types of yeast

How to deal with a Homophobic PC

Can an integer optimization problem be convex?

What is the difference between an astronaut in the ISS and a freediver in perfect neutral buoyancy?

Do wheelchair aircraft exist?



ggplot: customize the color of margins of dots


colors for two geom_point() in ggplot2 when using aes_stringIndividual Points Not Showing Up on Plotly (but do show up in ggplot2)Creating a ggplot legend with color and linetype based on two variablesHow to merge color, line style and shape legends in ggplotAggregating data with ggplotLegends for multiple fills in ggplotCreate annotation for a balloon plot from gplots packagechange color data points plotLearnerPrediction (MLR package)Add legends corresponding to the layers in ggplotChange fill color of dotplot_geom but retain fill color of boxplot






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I would like to customize the color of the margins of the dots of my ggplot. The color of the fill of dots summarize one information while
the color of the margins will summarize another one.



Suppose to use the mtcars data:



library(ggplot2)
ggplot(mtcars, aes(wt, mpg)) +
geom_point(aes(colour = factor(cyl), shape = factor(vs)))


Then suppose you want to modify the color of the margin of dots using the column mtcars$carb.



Is it possible using ggplot?










share|improve this question


























  • Do you also need to map something to shape?

    – PoGibas
    Mar 28 at 17:38












  • You need shapes that have a separate fill and border, like shapes 21:25. So you could use scale_shape_manual(values = c(21, 22, 23) ) or something and then use fill for carb.

    – aosmith
    Mar 28 at 17:38


















0















I would like to customize the color of the margins of the dots of my ggplot. The color of the fill of dots summarize one information while
the color of the margins will summarize another one.



Suppose to use the mtcars data:



library(ggplot2)
ggplot(mtcars, aes(wt, mpg)) +
geom_point(aes(colour = factor(cyl), shape = factor(vs)))


Then suppose you want to modify the color of the margin of dots using the column mtcars$carb.



Is it possible using ggplot?










share|improve this question


























  • Do you also need to map something to shape?

    – PoGibas
    Mar 28 at 17:38












  • You need shapes that have a separate fill and border, like shapes 21:25. So you could use scale_shape_manual(values = c(21, 22, 23) ) or something and then use fill for carb.

    – aosmith
    Mar 28 at 17:38














0












0








0


1






I would like to customize the color of the margins of the dots of my ggplot. The color of the fill of dots summarize one information while
the color of the margins will summarize another one.



Suppose to use the mtcars data:



library(ggplot2)
ggplot(mtcars, aes(wt, mpg)) +
geom_point(aes(colour = factor(cyl), shape = factor(vs)))


Then suppose you want to modify the color of the margin of dots using the column mtcars$carb.



Is it possible using ggplot?










share|improve this question
















I would like to customize the color of the margins of the dots of my ggplot. The color of the fill of dots summarize one information while
the color of the margins will summarize another one.



Suppose to use the mtcars data:



library(ggplot2)
ggplot(mtcars, aes(wt, mpg)) +
geom_point(aes(colour = factor(cyl), shape = factor(vs)))


Then suppose you want to modify the color of the margin of dots using the column mtcars$carb.



Is it possible using ggplot?







r ggplot2






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 28 at 17:38









PoGibas

19.2k16 gold badges50 silver badges83 bronze badges




19.2k16 gold badges50 silver badges83 bronze badges










asked Mar 28 at 17:32









Bnf8Bnf8

892 silver badges10 bronze badges




892 silver badges10 bronze badges















  • Do you also need to map something to shape?

    – PoGibas
    Mar 28 at 17:38












  • You need shapes that have a separate fill and border, like shapes 21:25. So you could use scale_shape_manual(values = c(21, 22, 23) ) or something and then use fill for carb.

    – aosmith
    Mar 28 at 17:38


















  • Do you also need to map something to shape?

    – PoGibas
    Mar 28 at 17:38












  • You need shapes that have a separate fill and border, like shapes 21:25. So you could use scale_shape_manual(values = c(21, 22, 23) ) or something and then use fill for carb.

    – aosmith
    Mar 28 at 17:38

















Do you also need to map something to shape?

– PoGibas
Mar 28 at 17:38






Do you also need to map something to shape?

– PoGibas
Mar 28 at 17:38














You need shapes that have a separate fill and border, like shapes 21:25. So you could use scale_shape_manual(values = c(21, 22, 23) ) or something and then use fill for carb.

– aosmith
Mar 28 at 17:38






You need shapes that have a separate fill and border, like shapes 21:25. So you could use scale_shape_manual(values = c(21, 22, 23) ) or something and then use fill for carb.

– aosmith
Mar 28 at 17:38













1 Answer
1






active

oldest

votes


















3
















Yes, you need to use fill for the inside color and color for the line color. And you need to use shapes that differentiate between the two (that is, shapes 21-25. Search "r pch" or see the help page at ?pch for all the shapes). Unfortunately, for the legends to look right, we need to manually specify shapes for the legends. You may also want to use at least one manual scale (e.g., scale_fill_manual) specifying your own colors so that the fill and line colors are more different.



ggplot(mtcars,
aes(
x = wt,
y = mpg,
color = factor(carb),
fill = factor(cyl),
shape = factor(vs)
)) + geom_point(size = 2, stroke = 1.5) +
scale_shape_manual(values = c(21, 24)) +
scale_fill_hue(guide = guide_legend(override.aes = list(shape = 21))) +
scale_color_hue(guide = guide_legend(override.aes = list(shape = 21)))


enter image description here
See also the example at the bottom of the ?geom_point help page:



# For shapes that have a border (like 21), you can colour the inside and
# outside separately. Use the stroke aesthetic to modify the width of the
# border
ggplot(mtcars, aes(wt, mpg)) +
geom_point(shape = 21, colour = "black", fill = "white", size = 5, stroke = 5)





share|improve this answer



























  • Do you know the reason why fill legend is all black?

    – PoGibas
    Mar 28 at 17:41











  • I usually end up having to use override.aes to get a proper "filled" shape for the fill legend.

    – aosmith
    Mar 28 at 17:41







  • 1





    Yeah, working on it...

    – Gregor
    Mar 28 at 17:46











  • Thank you very much Gregor!!! It worked!

    – Bnf8
    Mar 29 at 17:03












  • @Bnf8 Glad it helped. If you consider the issue solved, please "accept" the answer by clicking the checkmark next to the votes/score. This indicates you are not still looking for more answers (and gives us each a little reputation).

    – Gregor
    Apr 1 at 16:03













Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);














draft saved

draft discarded
















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55403708%2fggplot-customize-the-color-of-margins-of-dots%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









3
















Yes, you need to use fill for the inside color and color for the line color. And you need to use shapes that differentiate between the two (that is, shapes 21-25. Search "r pch" or see the help page at ?pch for all the shapes). Unfortunately, for the legends to look right, we need to manually specify shapes for the legends. You may also want to use at least one manual scale (e.g., scale_fill_manual) specifying your own colors so that the fill and line colors are more different.



ggplot(mtcars,
aes(
x = wt,
y = mpg,
color = factor(carb),
fill = factor(cyl),
shape = factor(vs)
)) + geom_point(size = 2, stroke = 1.5) +
scale_shape_manual(values = c(21, 24)) +
scale_fill_hue(guide = guide_legend(override.aes = list(shape = 21))) +
scale_color_hue(guide = guide_legend(override.aes = list(shape = 21)))


enter image description here
See also the example at the bottom of the ?geom_point help page:



# For shapes that have a border (like 21), you can colour the inside and
# outside separately. Use the stroke aesthetic to modify the width of the
# border
ggplot(mtcars, aes(wt, mpg)) +
geom_point(shape = 21, colour = "black", fill = "white", size = 5, stroke = 5)





share|improve this answer



























  • Do you know the reason why fill legend is all black?

    – PoGibas
    Mar 28 at 17:41











  • I usually end up having to use override.aes to get a proper "filled" shape for the fill legend.

    – aosmith
    Mar 28 at 17:41







  • 1





    Yeah, working on it...

    – Gregor
    Mar 28 at 17:46











  • Thank you very much Gregor!!! It worked!

    – Bnf8
    Mar 29 at 17:03












  • @Bnf8 Glad it helped. If you consider the issue solved, please "accept" the answer by clicking the checkmark next to the votes/score. This indicates you are not still looking for more answers (and gives us each a little reputation).

    – Gregor
    Apr 1 at 16:03















3
















Yes, you need to use fill for the inside color and color for the line color. And you need to use shapes that differentiate between the two (that is, shapes 21-25. Search "r pch" or see the help page at ?pch for all the shapes). Unfortunately, for the legends to look right, we need to manually specify shapes for the legends. You may also want to use at least one manual scale (e.g., scale_fill_manual) specifying your own colors so that the fill and line colors are more different.



ggplot(mtcars,
aes(
x = wt,
y = mpg,
color = factor(carb),
fill = factor(cyl),
shape = factor(vs)
)) + geom_point(size = 2, stroke = 1.5) +
scale_shape_manual(values = c(21, 24)) +
scale_fill_hue(guide = guide_legend(override.aes = list(shape = 21))) +
scale_color_hue(guide = guide_legend(override.aes = list(shape = 21)))


enter image description here
See also the example at the bottom of the ?geom_point help page:



# For shapes that have a border (like 21), you can colour the inside and
# outside separately. Use the stroke aesthetic to modify the width of the
# border
ggplot(mtcars, aes(wt, mpg)) +
geom_point(shape = 21, colour = "black", fill = "white", size = 5, stroke = 5)





share|improve this answer



























  • Do you know the reason why fill legend is all black?

    – PoGibas
    Mar 28 at 17:41











  • I usually end up having to use override.aes to get a proper "filled" shape for the fill legend.

    – aosmith
    Mar 28 at 17:41







  • 1





    Yeah, working on it...

    – Gregor
    Mar 28 at 17:46











  • Thank you very much Gregor!!! It worked!

    – Bnf8
    Mar 29 at 17:03












  • @Bnf8 Glad it helped. If you consider the issue solved, please "accept" the answer by clicking the checkmark next to the votes/score. This indicates you are not still looking for more answers (and gives us each a little reputation).

    – Gregor
    Apr 1 at 16:03













3














3










3









Yes, you need to use fill for the inside color and color for the line color. And you need to use shapes that differentiate between the two (that is, shapes 21-25. Search "r pch" or see the help page at ?pch for all the shapes). Unfortunately, for the legends to look right, we need to manually specify shapes for the legends. You may also want to use at least one manual scale (e.g., scale_fill_manual) specifying your own colors so that the fill and line colors are more different.



ggplot(mtcars,
aes(
x = wt,
y = mpg,
color = factor(carb),
fill = factor(cyl),
shape = factor(vs)
)) + geom_point(size = 2, stroke = 1.5) +
scale_shape_manual(values = c(21, 24)) +
scale_fill_hue(guide = guide_legend(override.aes = list(shape = 21))) +
scale_color_hue(guide = guide_legend(override.aes = list(shape = 21)))


enter image description here
See also the example at the bottom of the ?geom_point help page:



# For shapes that have a border (like 21), you can colour the inside and
# outside separately. Use the stroke aesthetic to modify the width of the
# border
ggplot(mtcars, aes(wt, mpg)) +
geom_point(shape = 21, colour = "black", fill = "white", size = 5, stroke = 5)





share|improve this answer















Yes, you need to use fill for the inside color and color for the line color. And you need to use shapes that differentiate between the two (that is, shapes 21-25. Search "r pch" or see the help page at ?pch for all the shapes). Unfortunately, for the legends to look right, we need to manually specify shapes for the legends. You may also want to use at least one manual scale (e.g., scale_fill_manual) specifying your own colors so that the fill and line colors are more different.



ggplot(mtcars,
aes(
x = wt,
y = mpg,
color = factor(carb),
fill = factor(cyl),
shape = factor(vs)
)) + geom_point(size = 2, stroke = 1.5) +
scale_shape_manual(values = c(21, 24)) +
scale_fill_hue(guide = guide_legend(override.aes = list(shape = 21))) +
scale_color_hue(guide = guide_legend(override.aes = list(shape = 21)))


enter image description here
See also the example at the bottom of the ?geom_point help page:



# For shapes that have a border (like 21), you can colour the inside and
# outside separately. Use the stroke aesthetic to modify the width of the
# border
ggplot(mtcars, aes(wt, mpg)) +
geom_point(shape = 21, colour = "black", fill = "white", size = 5, stroke = 5)






share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 28 at 17:51

























answered Mar 28 at 17:40









GregorGregor

74.8k13 gold badges103 silver badges199 bronze badges




74.8k13 gold badges103 silver badges199 bronze badges















  • Do you know the reason why fill legend is all black?

    – PoGibas
    Mar 28 at 17:41











  • I usually end up having to use override.aes to get a proper "filled" shape for the fill legend.

    – aosmith
    Mar 28 at 17:41







  • 1





    Yeah, working on it...

    – Gregor
    Mar 28 at 17:46











  • Thank you very much Gregor!!! It worked!

    – Bnf8
    Mar 29 at 17:03












  • @Bnf8 Glad it helped. If you consider the issue solved, please "accept" the answer by clicking the checkmark next to the votes/score. This indicates you are not still looking for more answers (and gives us each a little reputation).

    – Gregor
    Apr 1 at 16:03

















  • Do you know the reason why fill legend is all black?

    – PoGibas
    Mar 28 at 17:41











  • I usually end up having to use override.aes to get a proper "filled" shape for the fill legend.

    – aosmith
    Mar 28 at 17:41







  • 1





    Yeah, working on it...

    – Gregor
    Mar 28 at 17:46











  • Thank you very much Gregor!!! It worked!

    – Bnf8
    Mar 29 at 17:03












  • @Bnf8 Glad it helped. If you consider the issue solved, please "accept" the answer by clicking the checkmark next to the votes/score. This indicates you are not still looking for more answers (and gives us each a little reputation).

    – Gregor
    Apr 1 at 16:03
















Do you know the reason why fill legend is all black?

– PoGibas
Mar 28 at 17:41





Do you know the reason why fill legend is all black?

– PoGibas
Mar 28 at 17:41













I usually end up having to use override.aes to get a proper "filled" shape for the fill legend.

– aosmith
Mar 28 at 17:41






I usually end up having to use override.aes to get a proper "filled" shape for the fill legend.

– aosmith
Mar 28 at 17:41





1




1





Yeah, working on it...

– Gregor
Mar 28 at 17:46





Yeah, working on it...

– Gregor
Mar 28 at 17:46













Thank you very much Gregor!!! It worked!

– Bnf8
Mar 29 at 17:03






Thank you very much Gregor!!! It worked!

– Bnf8
Mar 29 at 17:03














@Bnf8 Glad it helped. If you consider the issue solved, please "accept" the answer by clicking the checkmark next to the votes/score. This indicates you are not still looking for more answers (and gives us each a little reputation).

– Gregor
Apr 1 at 16:03





@Bnf8 Glad it helped. If you consider the issue solved, please "accept" the answer by clicking the checkmark next to the votes/score. This indicates you are not still looking for more answers (and gives us each a little reputation).

– Gregor
Apr 1 at 16:03




















draft saved

draft discarded















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55403708%2fggplot-customize-the-color-of-margins-of-dots%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript