How to make a US map based on state-level data?Drop factor levels in a subsetted data frameHow to join (merge) data frames (inner, outer, left, right)How to make a great R reproducible exampleHow can we make xkcd style graphs?how do I match color palettes in multiple ggplot2 graphs in R?how to make a bar plot for a list of dataframes?Why can't I bind these data frames in R?Plot longitude-latitude points on a map with different colors for varying levels?Create data frame of names of 50 states in Rggplot2 & map filling colors in states in R studio

Taking my Ph.D. advisor out for dinner after graduation

What is the maximum amount of diamond in one Minecraft game?

Do intermediate subdomains need to exist?

How do I check that users don't write down their passwords?

Sleepy tired vs physically tired

Bypass with wrong cvv of debit card and getting OTP

What do I need to see before Spider-Man: Far From Home?

Why no parachutes in the Orion AA2 abort test?

Motorcyle Chain needs to be cleaned every time you lube it?

Should I increase my 401(k) contributions, or increase my mortgage payments

What is the fundamental difference between catching whales and hunting other animals?

Way to see all encrypted fields in Salesforce?

What are some bad ways to subvert tropes?

Can a Time Lord survive with just one heart?

Boss furious on bad appraisal

Who is responsible for exterminating cockroaches in house - tenant or landlord?

When is one 'Ready' to make Original Contributions to Mathematics?

Can you take the Dodge action while prone?

Is it acceptable that I plot a time-series figure with years increasing from right to left?

Is conquering your neighbors to fight a greater enemy a valid strategy?

How can I effectively map a multi-level dungeon?

Is it possible that Curiosity measured its own methane or failed doing the spectrometry?

Why do most airliners have underwing engines, while business jets have rear-mounted engines?

Was I wrongfully denied boarding for having a Schengen visa issued from the second country on my itinerary?



How to make a US map based on state-level data?


Drop factor levels in a subsetted data frameHow to join (merge) data frames (inner, outer, left, right)How to make a great R reproducible exampleHow can we make xkcd style graphs?how do I match color palettes in multiple ggplot2 graphs in R?how to make a bar plot for a list of dataframes?Why can't I bind these data frames in R?Plot longitude-latitude points on a map with different colors for varying levels?Create data frame of names of 50 states in Rggplot2 & map filling colors in states in R studio






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








2















I am trying to use ggplot2 to make a US map based on some state level data, and color each state based on the value of one variable.



State loan
AL 25310770
AK 45310770
AZ 35310770
AR 25682770
...


Edit: Thanks to @Hector Haffenden, the dput(head(your_data)) gives:



structure(list(state = c("AL", "AK", "AZ", "AR", "IL", "MA"), 
loan = c(25310770, 21230922, 15055436, 15212963, 12796921, 20311736),
row.names = c(NA, 6L), class = "data.frame")


Since I have a variable of state name, is it possible to automatically match each row to the map based on the state name abbreviations? Here is an example of my expected output:



https://i.imgur.com/0CD4fOx.png










share|improve this question
























  • Hello "The R", your question was well written. A potential improvement could be adding the results from dput(head(your_data)) to the question. This allows someone to copy paste a sample. Will get you a much faster and more accurate answer :) Thanks for the accept and welcome to stack.

    – Hector Haffenden
    Mar 25 at 19:37












  • @HectorHaffenden Thanks for your advice! I will do that!

    – The R
    Mar 25 at 19:46

















2















I am trying to use ggplot2 to make a US map based on some state level data, and color each state based on the value of one variable.



State loan
AL 25310770
AK 45310770
AZ 35310770
AR 25682770
...


Edit: Thanks to @Hector Haffenden, the dput(head(your_data)) gives:



structure(list(state = c("AL", "AK", "AZ", "AR", "IL", "MA"), 
loan = c(25310770, 21230922, 15055436, 15212963, 12796921, 20311736),
row.names = c(NA, 6L), class = "data.frame")


Since I have a variable of state name, is it possible to automatically match each row to the map based on the state name abbreviations? Here is an example of my expected output:



https://i.imgur.com/0CD4fOx.png










share|improve this question
























  • Hello "The R", your question was well written. A potential improvement could be adding the results from dput(head(your_data)) to the question. This allows someone to copy paste a sample. Will get you a much faster and more accurate answer :) Thanks for the accept and welcome to stack.

    – Hector Haffenden
    Mar 25 at 19:37












  • @HectorHaffenden Thanks for your advice! I will do that!

    – The R
    Mar 25 at 19:46













2












2








2








I am trying to use ggplot2 to make a US map based on some state level data, and color each state based on the value of one variable.



State loan
AL 25310770
AK 45310770
AZ 35310770
AR 25682770
...


Edit: Thanks to @Hector Haffenden, the dput(head(your_data)) gives:



structure(list(state = c("AL", "AK", "AZ", "AR", "IL", "MA"), 
loan = c(25310770, 21230922, 15055436, 15212963, 12796921, 20311736),
row.names = c(NA, 6L), class = "data.frame")


Since I have a variable of state name, is it possible to automatically match each row to the map based on the state name abbreviations? Here is an example of my expected output:



https://i.imgur.com/0CD4fOx.png










share|improve this question
















I am trying to use ggplot2 to make a US map based on some state level data, and color each state based on the value of one variable.



State loan
AL 25310770
AK 45310770
AZ 35310770
AR 25682770
...


Edit: Thanks to @Hector Haffenden, the dput(head(your_data)) gives:



structure(list(state = c("AL", "AK", "AZ", "AR", "IL", "MA"), 
loan = c(25310770, 21230922, 15055436, 15212963, 12796921, 20311736),
row.names = c(NA, 6L), class = "data.frame")


Since I have a variable of state name, is it possible to automatically match each row to the map based on the state name abbreviations? Here is an example of my expected output:



https://i.imgur.com/0CD4fOx.png







r ggplot2






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 25 at 19:50







The R

















asked Mar 25 at 19:18









The RThe R

155 bronze badges




155 bronze badges












  • Hello "The R", your question was well written. A potential improvement could be adding the results from dput(head(your_data)) to the question. This allows someone to copy paste a sample. Will get you a much faster and more accurate answer :) Thanks for the accept and welcome to stack.

    – Hector Haffenden
    Mar 25 at 19:37












  • @HectorHaffenden Thanks for your advice! I will do that!

    – The R
    Mar 25 at 19:46

















  • Hello "The R", your question was well written. A potential improvement could be adding the results from dput(head(your_data)) to the question. This allows someone to copy paste a sample. Will get you a much faster and more accurate answer :) Thanks for the accept and welcome to stack.

    – Hector Haffenden
    Mar 25 at 19:37












  • @HectorHaffenden Thanks for your advice! I will do that!

    – The R
    Mar 25 at 19:46
















Hello "The R", your question was well written. A potential improvement could be adding the results from dput(head(your_data)) to the question. This allows someone to copy paste a sample. Will get you a much faster and more accurate answer :) Thanks for the accept and welcome to stack.

– Hector Haffenden
Mar 25 at 19:37






Hello "The R", your question was well written. A potential improvement could be adding the results from dput(head(your_data)) to the question. This allows someone to copy paste a sample. Will get you a much faster and more accurate answer :) Thanks for the accept and welcome to stack.

– Hector Haffenden
Mar 25 at 19:37














@HectorHaffenden Thanks for your advice! I will do that!

– The R
Mar 25 at 19:46





@HectorHaffenden Thanks for your advice! I will do that!

– The R
Mar 25 at 19:46












1 Answer
1






active

oldest

votes


















2














Try this, first define our data like this,



dat <- data.frame(state = c("AL", "AK", "AZ", "AR"), Loan = c(25310770, 45310770, 35310770, 25682770))


Import the packages usmap and ggplot2, then, with more complete data, it will fill the whole map, but using the sample provided, we see



library(usmap)
library(ggplot2)

plot_usmap(
data = dat, values = "Loan", lines = "red"
) +
scale_fill_continuous(
low = "white", high = "red", name = "Loan", label = scales::comma
) +
labs(title = "US States", subtitle = "States and loan data") +
theme(legend.position = "right")


Note some states are grey due to small sample of data provided.



the map






share|improve this answer
























    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%2f55344991%2fhow-to-make-a-us-map-based-on-state-level-data%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














    Try this, first define our data like this,



    dat <- data.frame(state = c("AL", "AK", "AZ", "AR"), Loan = c(25310770, 45310770, 35310770, 25682770))


    Import the packages usmap and ggplot2, then, with more complete data, it will fill the whole map, but using the sample provided, we see



    library(usmap)
    library(ggplot2)

    plot_usmap(
    data = dat, values = "Loan", lines = "red"
    ) +
    scale_fill_continuous(
    low = "white", high = "red", name = "Loan", label = scales::comma
    ) +
    labs(title = "US States", subtitle = "States and loan data") +
    theme(legend.position = "right")


    Note some states are grey due to small sample of data provided.



    the map






    share|improve this answer





























      2














      Try this, first define our data like this,



      dat <- data.frame(state = c("AL", "AK", "AZ", "AR"), Loan = c(25310770, 45310770, 35310770, 25682770))


      Import the packages usmap and ggplot2, then, with more complete data, it will fill the whole map, but using the sample provided, we see



      library(usmap)
      library(ggplot2)

      plot_usmap(
      data = dat, values = "Loan", lines = "red"
      ) +
      scale_fill_continuous(
      low = "white", high = "red", name = "Loan", label = scales::comma
      ) +
      labs(title = "US States", subtitle = "States and loan data") +
      theme(legend.position = "right")


      Note some states are grey due to small sample of data provided.



      the map






      share|improve this answer



























        2












        2








        2







        Try this, first define our data like this,



        dat <- data.frame(state = c("AL", "AK", "AZ", "AR"), Loan = c(25310770, 45310770, 35310770, 25682770))


        Import the packages usmap and ggplot2, then, with more complete data, it will fill the whole map, but using the sample provided, we see



        library(usmap)
        library(ggplot2)

        plot_usmap(
        data = dat, values = "Loan", lines = "red"
        ) +
        scale_fill_continuous(
        low = "white", high = "red", name = "Loan", label = scales::comma
        ) +
        labs(title = "US States", subtitle = "States and loan data") +
        theme(legend.position = "right")


        Note some states are grey due to small sample of data provided.



        the map






        share|improve this answer















        Try this, first define our data like this,



        dat <- data.frame(state = c("AL", "AK", "AZ", "AR"), Loan = c(25310770, 45310770, 35310770, 25682770))


        Import the packages usmap and ggplot2, then, with more complete data, it will fill the whole map, but using the sample provided, we see



        library(usmap)
        library(ggplot2)

        plot_usmap(
        data = dat, values = "Loan", lines = "red"
        ) +
        scale_fill_continuous(
        low = "white", high = "red", name = "Loan", label = scales::comma
        ) +
        labs(title = "US States", subtitle = "States and loan data") +
        theme(legend.position = "right")


        Note some states are grey due to small sample of data provided.



        the map







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 25 at 19:32

























        answered Mar 25 at 19:25









        Hector HaffendenHector Haffenden

        9244 silver badges16 bronze badges




        9244 silver badges16 bronze badges


















            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%2f55344991%2fhow-to-make-a-us-map-based-on-state-level-data%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

            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

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현