Creating a map plot in R using plot_usmap package
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:
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
add a comment |
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:
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
5
What does "doesn't work" mean exactly? Do you get an error of some sort? What package does theplot_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 usedput
like earlier you did with theiris
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
add a comment |
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:
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
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:
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
r filter usmap
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 theplot_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 usedput
like earlier you did with theiris
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
add a comment |
5
What does "doesn't work" mean exactly? Do you get an error of some sort? What package does theplot_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 usedput
like earlier you did with theiris
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
add a comment |
1 Answer
1
active
oldest
votes
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.
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%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
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.
add a comment |
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.
add a comment |
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.
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.
answered Jan 7 at 15:21
PaoloPaolo
2,35331632
2,35331632
add a comment |
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%2f53328646%2fcreating-a-map-plot-in-r-using-plot-usmap-package%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
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 theiris
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