0

I am currently working on a project regarding the amount of executions happening in each U.S. state. I am working with the dataset from :https://deathpenaltyinfo.org/executions/execution-database. I used the usmap package from R to generate a map accordingly to my project. I found a guide on how to map U.S. states properly via Cran Project.

`plot_usmap(data = statepop, values = "pop_2015"., color = "red") + 
  scale_fill_continuous(name = "Executions ", label = scales::comma) + 
  theme(legend.position = "right")`

Is there a way to implement the execution amounts on my dataset on the usmap?

I tried something like this:

data = execdat %>% group_by(State) %>% summarise(Executions = n())
plot_usmap(data = data, values = data$Executions., color = "red") + 
  scale_fill_continuous(name = "Executions ", label = scales::comma) + 
  theme(legend.position = "right")

But I get an error code:

Error in map_with_data(data, values = values, include = include, exclude = exclude) : 
  "c("Alabama", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "Federal", "Florida", "Georgia", "Idaho", "Illinois", "Indiana", "Kentucky", "Louisiana", "Maryland", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada", "New Mexico", "North Carolina", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", "Virginia", "Washington", "Wyoming")" column not found in `data`."c(69, 37, 31, 13, 1, 1, 16, 16, 99, 76, 3, 12, 20, 3, 28, 5, 22, 91, 3, 4, 12, 1, 43, 56, 116, 2, 3, 43, 5, 13, 573, 7, 113, 5, 1)" column not found in `data`.
In addition: Warning message:
In if (!(values %in% names(data))) { :
  the condition has length > 1 and only the first element will be used

I want to have something like this: from reddit.com/MapPorn

Quinten
  • 35,235
  • 5
  • 20
  • 53
  • 1
    Hi @PythonG, could you please share your data using `dput(execdat)`? It is better to directly share your data than using a link. – Quinten Apr 02 '22 at 14:45
  • Hi Quinten I think the dataset is a little bit to big to share the whole dput. This should be the official csv Url for the dataset if this helps! Cheers! https://docs.google.com/spreadsheets/d/e/2PACX-1vQDMoiJXVldahXzL4S037MGb7DgZMfeqfrR-zYtDJ_U-Sd6FS35W7WU_6N8pXBOm9NOBGIM8BEui37x/pub?gid=0&single=true&output=csv – PythonG Apr 02 '22 at 14:50
  • 1
    @PythonG You can try `dput(head(execdat, 10))` for the first 10 rows of data. No need to share the entire dataset. It is preferred to share data in your post rather than through an external link. – Ben Apr 02 '22 at 15:39
  • 3
    Definitely look into this post: [How to label numbers instead of names using usmap?](https://stackoverflow.com/q/63488086/1422451) – Parfait Apr 02 '22 at 16:29
  • Thank you guys for your comments. I got the code fixed and its now working properly I am going to checkout Parfaits link about the number labeling for my map! And ty Ben! I didnt know I could sent only the first 10 rows will do this for my future questions – PythonG Apr 02 '22 at 22:30

0 Answers0