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;








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









share|improve this question






























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









    share|improve this question


























      0












      0








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









      share|improve this question














      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 28 at 2:50









      Michelle WardMichelle Ward

      115 bronze badges




      115 bronze badges

























          1 Answer
          1






          active

          oldest

          votes


















          2
















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





          share|improve this answer

























          • This is perfect! Thanks

            – Michelle Ward
            Mar 28 at 3:23










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



          );













          draft saved

          draft discarded


















          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









          2
















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





          share|improve this answer

























          • This is perfect! Thanks

            – Michelle Ward
            Mar 28 at 3:23















          2
















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





          share|improve this answer

























          • This is perfect! Thanks

            – Michelle Ward
            Mar 28 at 3:23













          2














          2










          2









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





          share|improve this answer













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






          share|improve this answer












          share|improve this answer



          share|improve this answer










          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

















          • 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








          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.



















          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%2f55389472%2fhow-to-specify-colours-in-scatterplot-quadrants%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

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

          155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해