Creating a map plot in R using plot_usmap package










2















I have a dataset containing different states, zip codes, and claim counts each in separate columns. I am trying to create a plot to show the total claim count according to zip codes for the state of MA.



Dataset:
enter image description here



I used this to filter by MA:



MA_medicare <- medicare %>%
filter(medicare$NPPES.Provider.State == "MA")


I then used this to set the fips code for plot_usmap:



MA_medicare$NPPES.Provider.State <- fips(MA_medicare$NPPES.Provider.State)
setnames(MA_medicare, old=c("NPPES.Provider.State"), new=c("fips"))


And last tried to graph (not sure why this doesn't work):



plot_usmap(data = MA_medicare, values= c("Total.Claim.Count", "NPPES.Provider.Zip.Code"), include = c("MA")) + scale_fill_continuous(low= "white", high= "red") + theme(legend.position = "right") 


Error: Aesthetics must be either length 1 or the same as the data (4350838): fill










share|improve this question



















  • 5





    What does "doesn't work" mean exactly? Do you get an error of some sort? What package does the plot_usmap function come from (that's not a base R function). It's easier to help you if you include a simple reproducible example with sample input and desired output that can be used to test and verify possible solutions.

    – MrFlick
    Nov 15 '18 at 22:19











  • @MrFlick I included more information now. The package I'm using is "usmap" and I'm the error im getting is: Error: Aesthetics must be either length 1 or the same as the data (4350838): fill

    – nathan
    Nov 15 '18 at 23:54











  • @www I apologize I was trying to reproduce the data set. I added a picture now of some of the rows and the columns I am trying to use.

    – nathan
    Nov 16 '18 at 1:11






  • 1





    Thanks for the update. It is a good idea to use dput like earlier you did with the iris data. Screenshot is a terrible way to share data because it is unlikely that someone is willing to type all the text based on your picture.

    – www
    Nov 16 '18 at 1:16















2















I have a dataset containing different states, zip codes, and claim counts each in separate columns. I am trying to create a plot to show the total claim count according to zip codes for the state of MA.



Dataset:
enter image description here



I used this to filter by MA:



MA_medicare <- medicare %>%
filter(medicare$NPPES.Provider.State == "MA")


I then used this to set the fips code for plot_usmap:



MA_medicare$NPPES.Provider.State <- fips(MA_medicare$NPPES.Provider.State)
setnames(MA_medicare, old=c("NPPES.Provider.State"), new=c("fips"))


And last tried to graph (not sure why this doesn't work):



plot_usmap(data = MA_medicare, values= c("Total.Claim.Count", "NPPES.Provider.Zip.Code"), include = c("MA")) + scale_fill_continuous(low= "white", high= "red") + theme(legend.position = "right") 


Error: Aesthetics must be either length 1 or the same as the data (4350838): fill










share|improve this question



















  • 5





    What does "doesn't work" mean exactly? Do you get an error of some sort? What package does the plot_usmap function come from (that's not a base R function). It's easier to help you if you include a simple reproducible example with sample input and desired output that can be used to test and verify possible solutions.

    – MrFlick
    Nov 15 '18 at 22:19











  • @MrFlick I included more information now. The package I'm using is "usmap" and I'm the error im getting is: Error: Aesthetics must be either length 1 or the same as the data (4350838): fill

    – nathan
    Nov 15 '18 at 23:54











  • @www I apologize I was trying to reproduce the data set. I added a picture now of some of the rows and the columns I am trying to use.

    – nathan
    Nov 16 '18 at 1:11






  • 1





    Thanks for the update. It is a good idea to use dput like earlier you did with the iris data. Screenshot is a terrible way to share data because it is unlikely that someone is willing to type all the text based on your picture.

    – www
    Nov 16 '18 at 1:16













2












2








2








I have a dataset containing different states, zip codes, and claim counts each in separate columns. I am trying to create a plot to show the total claim count according to zip codes for the state of MA.



Dataset:
enter image description here



I used this to filter by MA:



MA_medicare <- medicare %>%
filter(medicare$NPPES.Provider.State == "MA")


I then used this to set the fips code for plot_usmap:



MA_medicare$NPPES.Provider.State <- fips(MA_medicare$NPPES.Provider.State)
setnames(MA_medicare, old=c("NPPES.Provider.State"), new=c("fips"))


And last tried to graph (not sure why this doesn't work):



plot_usmap(data = MA_medicare, values= c("Total.Claim.Count", "NPPES.Provider.Zip.Code"), include = c("MA")) + scale_fill_continuous(low= "white", high= "red") + theme(legend.position = "right") 


Error: Aesthetics must be either length 1 or the same as the data (4350838): fill










share|improve this question
















I have a dataset containing different states, zip codes, and claim counts each in separate columns. I am trying to create a plot to show the total claim count according to zip codes for the state of MA.



Dataset:
enter image description here



I used this to filter by MA:



MA_medicare <- medicare %>%
filter(medicare$NPPES.Provider.State == "MA")


I then used this to set the fips code for plot_usmap:



MA_medicare$NPPES.Provider.State <- fips(MA_medicare$NPPES.Provider.State)
setnames(MA_medicare, old=c("NPPES.Provider.State"), new=c("fips"))


And last tried to graph (not sure why this doesn't work):



plot_usmap(data = MA_medicare, values= c("Total.Claim.Count", "NPPES.Provider.Zip.Code"), include = c("MA")) + scale_fill_continuous(low= "white", high= "red") + theme(legend.position = "right") 


Error: Aesthetics must be either length 1 or the same as the data (4350838): fill







r filter usmap






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 1:10







nathan

















asked Nov 15 '18 at 22:14









nathannathan

716




716







  • 5





    What does "doesn't work" mean exactly? Do you get an error of some sort? What package does the plot_usmap function come from (that's not a base R function). It's easier to help you if you include a simple reproducible example with sample input and desired output that can be used to test and verify possible solutions.

    – MrFlick
    Nov 15 '18 at 22:19











  • @MrFlick I included more information now. The package I'm using is "usmap" and I'm the error im getting is: Error: Aesthetics must be either length 1 or the same as the data (4350838): fill

    – nathan
    Nov 15 '18 at 23:54











  • @www I apologize I was trying to reproduce the data set. I added a picture now of some of the rows and the columns I am trying to use.

    – nathan
    Nov 16 '18 at 1:11






  • 1





    Thanks for the update. It is a good idea to use dput like earlier you did with the iris data. Screenshot is a terrible way to share data because it is unlikely that someone is willing to type all the text based on your picture.

    – www
    Nov 16 '18 at 1:16












  • 5





    What does "doesn't work" mean exactly? Do you get an error of some sort? What package does the plot_usmap function come from (that's not a base R function). It's easier to help you if you include a simple reproducible example with sample input and desired output that can be used to test and verify possible solutions.

    – MrFlick
    Nov 15 '18 at 22:19











  • @MrFlick I included more information now. The package I'm using is "usmap" and I'm the error im getting is: Error: Aesthetics must be either length 1 or the same as the data (4350838): fill

    – nathan
    Nov 15 '18 at 23:54











  • @www I apologize I was trying to reproduce the data set. I added a picture now of some of the rows and the columns I am trying to use.

    – nathan
    Nov 16 '18 at 1:11






  • 1





    Thanks for the update. It is a good idea to use dput like earlier you did with the iris data. Screenshot is a terrible way to share data because it is unlikely that someone is willing to type all the text based on your picture.

    – www
    Nov 16 '18 at 1:16







5




5





What does "doesn't work" mean exactly? Do you get an error of some sort? What package does the plot_usmap function come from (that's not a base R function). It's easier to help you if you include a simple reproducible example with sample input and desired output that can be used to test and verify possible solutions.

– MrFlick
Nov 15 '18 at 22:19





What does "doesn't work" mean exactly? Do you get an error of some sort? What package does the plot_usmap function come from (that's not a base R function). It's easier to help you if you include a simple reproducible example with sample input and desired output that can be used to test and verify possible solutions.

– MrFlick
Nov 15 '18 at 22:19













@MrFlick I included more information now. The package I'm using is "usmap" and I'm the error im getting is: Error: Aesthetics must be either length 1 or the same as the data (4350838): fill

– nathan
Nov 15 '18 at 23:54





@MrFlick I included more information now. The package I'm using is "usmap" and I'm the error im getting is: Error: Aesthetics must be either length 1 or the same as the data (4350838): fill

– nathan
Nov 15 '18 at 23:54













@www I apologize I was trying to reproduce the data set. I added a picture now of some of the rows and the columns I am trying to use.

– nathan
Nov 16 '18 at 1:11





@www I apologize I was trying to reproduce the data set. I added a picture now of some of the rows and the columns I am trying to use.

– nathan
Nov 16 '18 at 1:11




1




1





Thanks for the update. It is a good idea to use dput like earlier you did with the iris data. Screenshot is a terrible way to share data because it is unlikely that someone is willing to type all the text based on your picture.

– www
Nov 16 '18 at 1:16





Thanks for the update. It is a good idea to use dput like earlier you did with the iris data. Screenshot is a terrible way to share data because it is unlikely that someone is willing to type all the text based on your picture.

– www
Nov 16 '18 at 1:16












1 Answer
1






active

oldest

votes


















0














I'm the developer of usmap. plot_usmap only accepts one column of values for plotting so you're probably looking for the following:



plot_usmap(data = MA_medicare, values = "Total.Claim.Count", include = c("MA"))


However, your data is by zip code, and currently usmap doesn't support zip code maps (only state and county level maps). It uses the FIPS column to assign colors to states/counties on the map. Since you defined the FIPS codes by state, you'll just get the entire state of Massachusetts filled in with one solid color.






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%2f53328646%2fcreating-a-map-plot-in-r-using-plot-usmap-package%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









    0














    I'm the developer of usmap. plot_usmap only accepts one column of values for plotting so you're probably looking for the following:



    plot_usmap(data = MA_medicare, values = "Total.Claim.Count", include = c("MA"))


    However, your data is by zip code, and currently usmap doesn't support zip code maps (only state and county level maps). It uses the FIPS column to assign colors to states/counties on the map. Since you defined the FIPS codes by state, you'll just get the entire state of Massachusetts filled in with one solid color.






    share|improve this answer



























      0














      I'm the developer of usmap. plot_usmap only accepts one column of values for plotting so you're probably looking for the following:



      plot_usmap(data = MA_medicare, values = "Total.Claim.Count", include = c("MA"))


      However, your data is by zip code, and currently usmap doesn't support zip code maps (only state and county level maps). It uses the FIPS column to assign colors to states/counties on the map. Since you defined the FIPS codes by state, you'll just get the entire state of Massachusetts filled in with one solid color.






      share|improve this answer

























        0












        0








        0







        I'm the developer of usmap. plot_usmap only accepts one column of values for plotting so you're probably looking for the following:



        plot_usmap(data = MA_medicare, values = "Total.Claim.Count", include = c("MA"))


        However, your data is by zip code, and currently usmap doesn't support zip code maps (only state and county level maps). It uses the FIPS column to assign colors to states/counties on the map. Since you defined the FIPS codes by state, you'll just get the entire state of Massachusetts filled in with one solid color.






        share|improve this answer













        I'm the developer of usmap. plot_usmap only accepts one column of values for plotting so you're probably looking for the following:



        plot_usmap(data = MA_medicare, values = "Total.Claim.Count", include = c("MA"))


        However, your data is by zip code, and currently usmap doesn't support zip code maps (only state and county level maps). It uses the FIPS column to assign colors to states/counties on the map. Since you defined the FIPS codes by state, you'll just get the entire state of Massachusetts filled in with one solid color.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 7 at 15:21









        PaoloPaolo

        2,35331632




        2,35331632





























            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%2f53328646%2fcreating-a-map-plot-in-r-using-plot-usmap-package%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

            Top Tejano songwriter Luis Silva dead of heart attack at 64

            ReactJS Fetched API data displays live - need Data displayed static

            政党