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;
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
add a comment
|
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
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 usescale_shape_manual(values = c(21, 22, 23) )
or something and then usefill
forcarb
.
– aosmith
Mar 28 at 17:38
add a comment
|
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
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
r ggplot2
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 usescale_shape_manual(values = c(21, 22, 23) )
or something and then usefill
forcarb
.
– aosmith
Mar 28 at 17:38
add a comment
|
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 usescale_shape_manual(values = c(21, 22, 23) )
or something and then usefill
forcarb
.
– 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
add a comment
|
1 Answer
1
active
oldest
votes
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)))
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)
Do you know the reason why fill legend is all black?
– PoGibas
Mar 28 at 17:41
I usually end up having to useoverride.aes
to get a proper "filled" shape for thefill
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
add a comment
|
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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)))
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)
Do you know the reason why fill legend is all black?
– PoGibas
Mar 28 at 17:41
I usually end up having to useoverride.aes
to get a proper "filled" shape for thefill
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
add a comment
|
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)))
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)
Do you know the reason why fill legend is all black?
– PoGibas
Mar 28 at 17:41
I usually end up having to useoverride.aes
to get a proper "filled" shape for thefill
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
add a comment
|
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)))
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)
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)))
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)
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 useoverride.aes
to get a proper "filled" shape for thefill
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
add a comment
|
Do you know the reason why fill legend is all black?
– PoGibas
Mar 28 at 17:41
I usually end up having to useoverride.aes
to get a proper "filled" shape for thefill
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
add a comment
|
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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 usefill
forcarb
.– aosmith
Mar 28 at 17:38