how to specify colours in scatterplot quadrants?How to make a great R reproducible exampleScatterplot with marginal histograms in ggplot2How can we make xkcd style graphs?colors for two geom_point() in ggplot2 when using aes_stringR ggplot2 set color line by variable without groupingColour of geom_hline is not correct in legend [ggplot2]How to add manual colors for a ggplot2 (geom_smooth/geom_line)Creating a line chart in r for the average value of groupsMapping Raster Data Using ggplot2 with Multiple Color Scaleshow to define a range on x axis in ggplot2 using two columns of a data table
Is there any reason to change the ISO manually?
What did Boris Johnson mean when he said "extra 34 billion going into the NHS"
What exactly is a softlock?
Does this bike use hydraulic brakes?
Real-world issues with using an alias
Why not use futuristic pavise ballistic shields for protection?
Does immunity to damage from nonmagical attacks negate a rogue's Sneak Attack damage?
Why did the VIC-II and SID use 6 µm technology in the era of 3 µm and 1.5 µm?
How to find better food in airports
What is the difference between "wie" and "nach" in "Klingt wie/nach..."
Were the women of Travancore, India, taxed for covering their breasts by breast size?
Why don't they build airplanes from 3D printer plastic?
Can there be plants on the dark side of a tidally locked world?
Do I need to get a noble in order to win Splendor?
What is the significance of 104%?
How do I stop making people jump at home and at work?
How to generate all 3×3 matrices with a,a,a,a,b,b,b,c,c?
'Hard work never hurt anyone' Why not 'hurts'?
Count rook moves 1D
Are there photos of the Apollo LM showing disturbed lunar soil resulting from descent engine exhaust?
What does "se jouer" mean here?
What happens if I double Meddling Mage's 'enter the battlefield' trigger?
Did Alan Turing's student Robin Gandy assert that Charles Babbage had no notion of a universal computing machine?
Question about derivation of kinematics equations
how to specify colours in scatterplot quadrants?
How to make a great R reproducible exampleScatterplot with marginal histograms in ggplot2How can we make xkcd style graphs?colors for two geom_point() in ggplot2 when using aes_stringR ggplot2 set color line by variable without groupingColour of geom_hline is not correct in legend [ggplot2]How to add manual colors for a ggplot2 (geom_smooth/geom_line)Creating a line chart in r for the average value of groupsMapping Raster Data Using ggplot2 with Multiple Color Scaleshow to define a range on x axis in ggplot2 using two columns of a data table
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I'm looking to create a scatterplot within R that has points that are split into four quadrants and then applies a color to each quadrant based on group.
I have used the following code which works, but need to change the colours.
x_mid <- mean(c(max(iris$Petal.Length, na.rm = TRUE),
min(iris$Petal.Length, na.rm = TRUE)))
y_mid <- mean(c(max(iris$Petal.Width, na.rm = TRUE),
min(iris$Petal.Width, na.rm = TRUE)))
library(dplyr)
library(ggplot2)
iris %>%
mutate(quadrant = case_when(Petal.Length > x_mid & Petal.Width > y_mid ~ "Q1",
Petal.Length <= x_mid & Petal.Width > y_mid ~ "Q2",
Petal.Length <= x_mid & Petal.Width <= y_mid ~ "Q3",
TRUE ~ "Q4")) %>%
ggplot(aes(x = Petal.Length, y = Petal.Width, color = quadrant)) +
geom_vline(xintercept = x_mid) + # plot vertical line
geom_hline(yintercept = y_mid) + # plot horizontal line
geom_point()
r ggplot2 scatter-plot
add a comment |
I'm looking to create a scatterplot within R that has points that are split into four quadrants and then applies a color to each quadrant based on group.
I have used the following code which works, but need to change the colours.
x_mid <- mean(c(max(iris$Petal.Length, na.rm = TRUE),
min(iris$Petal.Length, na.rm = TRUE)))
y_mid <- mean(c(max(iris$Petal.Width, na.rm = TRUE),
min(iris$Petal.Width, na.rm = TRUE)))
library(dplyr)
library(ggplot2)
iris %>%
mutate(quadrant = case_when(Petal.Length > x_mid & Petal.Width > y_mid ~ "Q1",
Petal.Length <= x_mid & Petal.Width > y_mid ~ "Q2",
Petal.Length <= x_mid & Petal.Width <= y_mid ~ "Q3",
TRUE ~ "Q4")) %>%
ggplot(aes(x = Petal.Length, y = Petal.Width, color = quadrant)) +
geom_vline(xintercept = x_mid) + # plot vertical line
geom_hline(yintercept = y_mid) + # plot horizontal line
geom_point()
r ggplot2 scatter-plot
add a comment |
I'm looking to create a scatterplot within R that has points that are split into four quadrants and then applies a color to each quadrant based on group.
I have used the following code which works, but need to change the colours.
x_mid <- mean(c(max(iris$Petal.Length, na.rm = TRUE),
min(iris$Petal.Length, na.rm = TRUE)))
y_mid <- mean(c(max(iris$Petal.Width, na.rm = TRUE),
min(iris$Petal.Width, na.rm = TRUE)))
library(dplyr)
library(ggplot2)
iris %>%
mutate(quadrant = case_when(Petal.Length > x_mid & Petal.Width > y_mid ~ "Q1",
Petal.Length <= x_mid & Petal.Width > y_mid ~ "Q2",
Petal.Length <= x_mid & Petal.Width <= y_mid ~ "Q3",
TRUE ~ "Q4")) %>%
ggplot(aes(x = Petal.Length, y = Petal.Width, color = quadrant)) +
geom_vline(xintercept = x_mid) + # plot vertical line
geom_hline(yintercept = y_mid) + # plot horizontal line
geom_point()
r ggplot2 scatter-plot
I'm looking to create a scatterplot within R that has points that are split into four quadrants and then applies a color to each quadrant based on group.
I have used the following code which works, but need to change the colours.
x_mid <- mean(c(max(iris$Petal.Length, na.rm = TRUE),
min(iris$Petal.Length, na.rm = TRUE)))
y_mid <- mean(c(max(iris$Petal.Width, na.rm = TRUE),
min(iris$Petal.Width, na.rm = TRUE)))
library(dplyr)
library(ggplot2)
iris %>%
mutate(quadrant = case_when(Petal.Length > x_mid & Petal.Width > y_mid ~ "Q1",
Petal.Length <= x_mid & Petal.Width > y_mid ~ "Q2",
Petal.Length <= x_mid & Petal.Width <= y_mid ~ "Q3",
TRUE ~ "Q4")) %>%
ggplot(aes(x = Petal.Length, y = Petal.Width, color = quadrant)) +
geom_vline(xintercept = x_mid) + # plot vertical line
geom_hline(yintercept = y_mid) + # plot horizontal line
geom_point()
r ggplot2 scatter-plot
r ggplot2 scatter-plot
asked Mar 28 at 2:50
Michelle WardMichelle Ward
115 bronze badges
115 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
If I understood correctly, the only thing that is missing is the manual selection of the colors, in which case the fact that the colors come from quadrants is incidental. Otherwise, I'm afraid I'm missing something.
You can specify the color scale like any other aesthetic. In particular, scale_color_manual lets you give it a vector of strings specifying the colors to use.
So you can add at the end:
scale_color_manual(values = c('orange', 'yellow', 'black', 'grey'))
You you want to map a specific color to each possible level, you can give it a named vector:
scale_color_manual(values = c(Q4 = 'orange', Q2 = 'yellow', Q1 = 'black', Q3 = 'grey'))
This is perfect! Thanks
– Michelle Ward
Mar 28 at 3:23
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/3.0/"u003ecc by-sa 3.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%2f55389472%2fhow-to-specify-colours-in-scatterplot-quadrants%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
If I understood correctly, the only thing that is missing is the manual selection of the colors, in which case the fact that the colors come from quadrants is incidental. Otherwise, I'm afraid I'm missing something.
You can specify the color scale like any other aesthetic. In particular, scale_color_manual lets you give it a vector of strings specifying the colors to use.
So you can add at the end:
scale_color_manual(values = c('orange', 'yellow', 'black', 'grey'))
You you want to map a specific color to each possible level, you can give it a named vector:
scale_color_manual(values = c(Q4 = 'orange', Q2 = 'yellow', Q1 = 'black', Q3 = 'grey'))
This is perfect! Thanks
– Michelle Ward
Mar 28 at 3:23
add a comment |
If I understood correctly, the only thing that is missing is the manual selection of the colors, in which case the fact that the colors come from quadrants is incidental. Otherwise, I'm afraid I'm missing something.
You can specify the color scale like any other aesthetic. In particular, scale_color_manual lets you give it a vector of strings specifying the colors to use.
So you can add at the end:
scale_color_manual(values = c('orange', 'yellow', 'black', 'grey'))
You you want to map a specific color to each possible level, you can give it a named vector:
scale_color_manual(values = c(Q4 = 'orange', Q2 = 'yellow', Q1 = 'black', Q3 = 'grey'))
This is perfect! Thanks
– Michelle Ward
Mar 28 at 3:23
add a comment |
If I understood correctly, the only thing that is missing is the manual selection of the colors, in which case the fact that the colors come from quadrants is incidental. Otherwise, I'm afraid I'm missing something.
You can specify the color scale like any other aesthetic. In particular, scale_color_manual lets you give it a vector of strings specifying the colors to use.
So you can add at the end:
scale_color_manual(values = c('orange', 'yellow', 'black', 'grey'))
You you want to map a specific color to each possible level, you can give it a named vector:
scale_color_manual(values = c(Q4 = 'orange', Q2 = 'yellow', Q1 = 'black', Q3 = 'grey'))
If I understood correctly, the only thing that is missing is the manual selection of the colors, in which case the fact that the colors come from quadrants is incidental. Otherwise, I'm afraid I'm missing something.
You can specify the color scale like any other aesthetic. In particular, scale_color_manual lets you give it a vector of strings specifying the colors to use.
So you can add at the end:
scale_color_manual(values = c('orange', 'yellow', 'black', 'grey'))
You you want to map a specific color to each possible level, you can give it a named vector:
scale_color_manual(values = c(Q4 = 'orange', Q2 = 'yellow', Q1 = 'black', Q3 = 'grey'))
answered Mar 28 at 3:09
mgiormentimgiormenti
5972 silver badges12 bronze badges
5972 silver badges12 bronze badges
This is perfect! Thanks
– Michelle Ward
Mar 28 at 3:23
add a comment |
This is perfect! Thanks
– Michelle Ward
Mar 28 at 3:23
This is perfect! Thanks
– Michelle Ward
Mar 28 at 3:23
This is perfect! Thanks
– Michelle Ward
Mar 28 at 3:23
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
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%2f55389472%2fhow-to-specify-colours-in-scatterplot-quadrants%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