How to plot arrest rate (%) for the top 20 crime types (crimes of chicago dataset)?












-2














I am working with R in RStudio and would like to plot via highchart package a graphic that includes on the x-Axis the crime type, and on the y-Axis the arrest rate in %. So to see on which crime type the highest arrest was made. I am working with following code in shiny, which is working but not ploting what exactly I want:



output$top20arrestCrime <- renderHighchart({
arrestCrimeAnalysis <- cc %>%
group_by(Primary.Type, Arrest == TRUE) %>%
summarise(Total = n()) %>%
arrange(desc(Total))

hchart(arrestCrimeAnalysis, "column", hcaes(x = Primary.Type, y = Total, color = Total)) %>%
hc_exporting(enabled = TRUE, filename = "Top_20_Locations") %>%
hc_title(text = "Top 20 Crime Types") %>%
hc_subtitle(text = "(2001 - 2016)") %>%
hc_xAxis(title = list(text = "Crime Type"), labels = list(rotation = -90)) %>%
hc_yAxis(title = list(text = "Arrest Rate %")) %>%
hc_colorAxis(stops = color_stops(n = 10, colors = c("#d98880", "#85c1e9", "#82e0aa"))) %>%
hc_add_theme(hc_theme_smpl()) %>%
hc_legend(enabled = FALSE)
})


I am working with this dataset: https://www.kaggle.com/currie32/crimes-in-chicago.



when I run the code, it just show me on the x-Axis the crime type (e.g. THEFT, ROBERRY) etc, which is correct and on the y-Axis the sum of thefts for example from 2001-2016. But I want on the y-Axis the Arrest Rate in percentage, so how many arrests happened. and this in a highcharter with the top 20 arrests crime types.



Example screenshot of Shiny app



img










share|improve this question




















  • 2




    "It doesn't do exactly what I want" is not a usable problem statement. You need to specify exactly what it is not doing.
    – Robert Harvey
    Dec 27 '18 at 18:11










  • @RobertHarvey when I run the code, it just show me on the x-Axis the crime type (e.g. THEFT, ROBERRY) etc, which is correct and on the y-Axis the sum of thefts for example from 2001-2016. But I want on the y-Axis the Arrest Rate in percentage, so how many arrests happened. and this in a highcharter with the top 20 arrests crime types.
    – S002
    Dec 27 '18 at 18:21










  • Include that information in your question. A picture of what you're talking about would be nice, too.
    – Robert Harvey
    Dec 27 '18 at 18:22










  • @RobertHarvey I did.
    – S002
    Dec 27 '18 at 18:52






  • 1




    Why is this tagged ggplot2?
    – camille
    Dec 27 '18 at 18:52
















-2














I am working with R in RStudio and would like to plot via highchart package a graphic that includes on the x-Axis the crime type, and on the y-Axis the arrest rate in %. So to see on which crime type the highest arrest was made. I am working with following code in shiny, which is working but not ploting what exactly I want:



output$top20arrestCrime <- renderHighchart({
arrestCrimeAnalysis <- cc %>%
group_by(Primary.Type, Arrest == TRUE) %>%
summarise(Total = n()) %>%
arrange(desc(Total))

hchart(arrestCrimeAnalysis, "column", hcaes(x = Primary.Type, y = Total, color = Total)) %>%
hc_exporting(enabled = TRUE, filename = "Top_20_Locations") %>%
hc_title(text = "Top 20 Crime Types") %>%
hc_subtitle(text = "(2001 - 2016)") %>%
hc_xAxis(title = list(text = "Crime Type"), labels = list(rotation = -90)) %>%
hc_yAxis(title = list(text = "Arrest Rate %")) %>%
hc_colorAxis(stops = color_stops(n = 10, colors = c("#d98880", "#85c1e9", "#82e0aa"))) %>%
hc_add_theme(hc_theme_smpl()) %>%
hc_legend(enabled = FALSE)
})


I am working with this dataset: https://www.kaggle.com/currie32/crimes-in-chicago.



when I run the code, it just show me on the x-Axis the crime type (e.g. THEFT, ROBERRY) etc, which is correct and on the y-Axis the sum of thefts for example from 2001-2016. But I want on the y-Axis the Arrest Rate in percentage, so how many arrests happened. and this in a highcharter with the top 20 arrests crime types.



Example screenshot of Shiny app



img










share|improve this question




















  • 2




    "It doesn't do exactly what I want" is not a usable problem statement. You need to specify exactly what it is not doing.
    – Robert Harvey
    Dec 27 '18 at 18:11










  • @RobertHarvey when I run the code, it just show me on the x-Axis the crime type (e.g. THEFT, ROBERRY) etc, which is correct and on the y-Axis the sum of thefts for example from 2001-2016. But I want on the y-Axis the Arrest Rate in percentage, so how many arrests happened. and this in a highcharter with the top 20 arrests crime types.
    – S002
    Dec 27 '18 at 18:21










  • Include that information in your question. A picture of what you're talking about would be nice, too.
    – Robert Harvey
    Dec 27 '18 at 18:22










  • @RobertHarvey I did.
    – S002
    Dec 27 '18 at 18:52






  • 1




    Why is this tagged ggplot2?
    – camille
    Dec 27 '18 at 18:52














-2












-2








-2







I am working with R in RStudio and would like to plot via highchart package a graphic that includes on the x-Axis the crime type, and on the y-Axis the arrest rate in %. So to see on which crime type the highest arrest was made. I am working with following code in shiny, which is working but not ploting what exactly I want:



output$top20arrestCrime <- renderHighchart({
arrestCrimeAnalysis <- cc %>%
group_by(Primary.Type, Arrest == TRUE) %>%
summarise(Total = n()) %>%
arrange(desc(Total))

hchart(arrestCrimeAnalysis, "column", hcaes(x = Primary.Type, y = Total, color = Total)) %>%
hc_exporting(enabled = TRUE, filename = "Top_20_Locations") %>%
hc_title(text = "Top 20 Crime Types") %>%
hc_subtitle(text = "(2001 - 2016)") %>%
hc_xAxis(title = list(text = "Crime Type"), labels = list(rotation = -90)) %>%
hc_yAxis(title = list(text = "Arrest Rate %")) %>%
hc_colorAxis(stops = color_stops(n = 10, colors = c("#d98880", "#85c1e9", "#82e0aa"))) %>%
hc_add_theme(hc_theme_smpl()) %>%
hc_legend(enabled = FALSE)
})


I am working with this dataset: https://www.kaggle.com/currie32/crimes-in-chicago.



when I run the code, it just show me on the x-Axis the crime type (e.g. THEFT, ROBERRY) etc, which is correct and on the y-Axis the sum of thefts for example from 2001-2016. But I want on the y-Axis the Arrest Rate in percentage, so how many arrests happened. and this in a highcharter with the top 20 arrests crime types.



Example screenshot of Shiny app



img










share|improve this question















I am working with R in RStudio and would like to plot via highchart package a graphic that includes on the x-Axis the crime type, and on the y-Axis the arrest rate in %. So to see on which crime type the highest arrest was made. I am working with following code in shiny, which is working but not ploting what exactly I want:



output$top20arrestCrime <- renderHighchart({
arrestCrimeAnalysis <- cc %>%
group_by(Primary.Type, Arrest == TRUE) %>%
summarise(Total = n()) %>%
arrange(desc(Total))

hchart(arrestCrimeAnalysis, "column", hcaes(x = Primary.Type, y = Total, color = Total)) %>%
hc_exporting(enabled = TRUE, filename = "Top_20_Locations") %>%
hc_title(text = "Top 20 Crime Types") %>%
hc_subtitle(text = "(2001 - 2016)") %>%
hc_xAxis(title = list(text = "Crime Type"), labels = list(rotation = -90)) %>%
hc_yAxis(title = list(text = "Arrest Rate %")) %>%
hc_colorAxis(stops = color_stops(n = 10, colors = c("#d98880", "#85c1e9", "#82e0aa"))) %>%
hc_add_theme(hc_theme_smpl()) %>%
hc_legend(enabled = FALSE)
})


I am working with this dataset: https://www.kaggle.com/currie32/crimes-in-chicago.



when I run the code, it just show me on the x-Axis the crime type (e.g. THEFT, ROBERRY) etc, which is correct and on the y-Axis the sum of thefts for example from 2001-2016. But I want on the y-Axis the Arrest Rate in percentage, so how many arrests happened. and this in a highcharter with the top 20 arrests crime types.



Example screenshot of Shiny app



img







r plot highcharts summarize






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 27 '18 at 20:24









PoGibas

15.5k134175




15.5k134175










asked Dec 27 '18 at 18:10









S002

45




45








  • 2




    "It doesn't do exactly what I want" is not a usable problem statement. You need to specify exactly what it is not doing.
    – Robert Harvey
    Dec 27 '18 at 18:11










  • @RobertHarvey when I run the code, it just show me on the x-Axis the crime type (e.g. THEFT, ROBERRY) etc, which is correct and on the y-Axis the sum of thefts for example from 2001-2016. But I want on the y-Axis the Arrest Rate in percentage, so how many arrests happened. and this in a highcharter with the top 20 arrests crime types.
    – S002
    Dec 27 '18 at 18:21










  • Include that information in your question. A picture of what you're talking about would be nice, too.
    – Robert Harvey
    Dec 27 '18 at 18:22










  • @RobertHarvey I did.
    – S002
    Dec 27 '18 at 18:52






  • 1




    Why is this tagged ggplot2?
    – camille
    Dec 27 '18 at 18:52














  • 2




    "It doesn't do exactly what I want" is not a usable problem statement. You need to specify exactly what it is not doing.
    – Robert Harvey
    Dec 27 '18 at 18:11










  • @RobertHarvey when I run the code, it just show me on the x-Axis the crime type (e.g. THEFT, ROBERRY) etc, which is correct and on the y-Axis the sum of thefts for example from 2001-2016. But I want on the y-Axis the Arrest Rate in percentage, so how many arrests happened. and this in a highcharter with the top 20 arrests crime types.
    – S002
    Dec 27 '18 at 18:21










  • Include that information in your question. A picture of what you're talking about would be nice, too.
    – Robert Harvey
    Dec 27 '18 at 18:22










  • @RobertHarvey I did.
    – S002
    Dec 27 '18 at 18:52






  • 1




    Why is this tagged ggplot2?
    – camille
    Dec 27 '18 at 18:52








2




2




"It doesn't do exactly what I want" is not a usable problem statement. You need to specify exactly what it is not doing.
– Robert Harvey
Dec 27 '18 at 18:11




"It doesn't do exactly what I want" is not a usable problem statement. You need to specify exactly what it is not doing.
– Robert Harvey
Dec 27 '18 at 18:11












@RobertHarvey when I run the code, it just show me on the x-Axis the crime type (e.g. THEFT, ROBERRY) etc, which is correct and on the y-Axis the sum of thefts for example from 2001-2016. But I want on the y-Axis the Arrest Rate in percentage, so how many arrests happened. and this in a highcharter with the top 20 arrests crime types.
– S002
Dec 27 '18 at 18:21




@RobertHarvey when I run the code, it just show me on the x-Axis the crime type (e.g. THEFT, ROBERRY) etc, which is correct and on the y-Axis the sum of thefts for example from 2001-2016. But I want on the y-Axis the Arrest Rate in percentage, so how many arrests happened. and this in a highcharter with the top 20 arrests crime types.
– S002
Dec 27 '18 at 18:21












Include that information in your question. A picture of what you're talking about would be nice, too.
– Robert Harvey
Dec 27 '18 at 18:22




Include that information in your question. A picture of what you're talking about would be nice, too.
– Robert Harvey
Dec 27 '18 at 18:22












@RobertHarvey I did.
– S002
Dec 27 '18 at 18:52




@RobertHarvey I did.
– S002
Dec 27 '18 at 18:52




1




1




Why is this tagged ggplot2?
– camille
Dec 27 '18 at 18:52




Why is this tagged ggplot2?
– camille
Dec 27 '18 at 18:52












1 Answer
1






active

oldest

votes


















0














Your problem is you haven't told highcharter to put Arrest Rate on the y axis. You've told it to put Total on the y axis:



arrestCrimeAnalysis <- cc %>% 
group_by(Primary.Type, Arrest == TRUE) %>%
summarise(Total = n()) %>%
arrange(desc(Total))
hchart(arrestCrimeAnalysis, "column", hcaes(x = Primary.Type, y = Total, color = Total))


Change y = Total to y = ArrestRate or whatever your rate column name is.






share|improve this answer





















  • thanks for your answer sastrup. I only have a column named "Arrest" which is filled with value of "TRUE" or "FALSE". I dont have any arrest rate column. What should I put in y in my case?
    – S002
    Dec 29 '18 at 18:45










  • Then you need to define an arrest rate calculation. It won’t just appear. What do you define as arrest rate? Will it be [# records where Arrest = True] / [# records]?
    – sastrup
    Dec 29 '18 at 18:50











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%2f53949144%2fhow-to-plot-arrest-rate-for-the-top-20-crime-types-crimes-of-chicago-datase%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














Your problem is you haven't told highcharter to put Arrest Rate on the y axis. You've told it to put Total on the y axis:



arrestCrimeAnalysis <- cc %>% 
group_by(Primary.Type, Arrest == TRUE) %>%
summarise(Total = n()) %>%
arrange(desc(Total))
hchart(arrestCrimeAnalysis, "column", hcaes(x = Primary.Type, y = Total, color = Total))


Change y = Total to y = ArrestRate or whatever your rate column name is.






share|improve this answer





















  • thanks for your answer sastrup. I only have a column named "Arrest" which is filled with value of "TRUE" or "FALSE". I dont have any arrest rate column. What should I put in y in my case?
    – S002
    Dec 29 '18 at 18:45










  • Then you need to define an arrest rate calculation. It won’t just appear. What do you define as arrest rate? Will it be [# records where Arrest = True] / [# records]?
    – sastrup
    Dec 29 '18 at 18:50
















0














Your problem is you haven't told highcharter to put Arrest Rate on the y axis. You've told it to put Total on the y axis:



arrestCrimeAnalysis <- cc %>% 
group_by(Primary.Type, Arrest == TRUE) %>%
summarise(Total = n()) %>%
arrange(desc(Total))
hchart(arrestCrimeAnalysis, "column", hcaes(x = Primary.Type, y = Total, color = Total))


Change y = Total to y = ArrestRate or whatever your rate column name is.






share|improve this answer





















  • thanks for your answer sastrup. I only have a column named "Arrest" which is filled with value of "TRUE" or "FALSE". I dont have any arrest rate column. What should I put in y in my case?
    – S002
    Dec 29 '18 at 18:45










  • Then you need to define an arrest rate calculation. It won’t just appear. What do you define as arrest rate? Will it be [# records where Arrest = True] / [# records]?
    – sastrup
    Dec 29 '18 at 18:50














0












0








0






Your problem is you haven't told highcharter to put Arrest Rate on the y axis. You've told it to put Total on the y axis:



arrestCrimeAnalysis <- cc %>% 
group_by(Primary.Type, Arrest == TRUE) %>%
summarise(Total = n()) %>%
arrange(desc(Total))
hchart(arrestCrimeAnalysis, "column", hcaes(x = Primary.Type, y = Total, color = Total))


Change y = Total to y = ArrestRate or whatever your rate column name is.






share|improve this answer












Your problem is you haven't told highcharter to put Arrest Rate on the y axis. You've told it to put Total on the y axis:



arrestCrimeAnalysis <- cc %>% 
group_by(Primary.Type, Arrest == TRUE) %>%
summarise(Total = n()) %>%
arrange(desc(Total))
hchart(arrestCrimeAnalysis, "column", hcaes(x = Primary.Type, y = Total, color = Total))


Change y = Total to y = ArrestRate or whatever your rate column name is.







share|improve this answer












share|improve this answer



share|improve this answer










answered Dec 28 '18 at 15:46









sastrup

779




779












  • thanks for your answer sastrup. I only have a column named "Arrest" which is filled with value of "TRUE" or "FALSE". I dont have any arrest rate column. What should I put in y in my case?
    – S002
    Dec 29 '18 at 18:45










  • Then you need to define an arrest rate calculation. It won’t just appear. What do you define as arrest rate? Will it be [# records where Arrest = True] / [# records]?
    – sastrup
    Dec 29 '18 at 18:50


















  • thanks for your answer sastrup. I only have a column named "Arrest" which is filled with value of "TRUE" or "FALSE". I dont have any arrest rate column. What should I put in y in my case?
    – S002
    Dec 29 '18 at 18:45










  • Then you need to define an arrest rate calculation. It won’t just appear. What do you define as arrest rate? Will it be [# records where Arrest = True] / [# records]?
    – sastrup
    Dec 29 '18 at 18:50
















thanks for your answer sastrup. I only have a column named "Arrest" which is filled with value of "TRUE" or "FALSE". I dont have any arrest rate column. What should I put in y in my case?
– S002
Dec 29 '18 at 18:45




thanks for your answer sastrup. I only have a column named "Arrest" which is filled with value of "TRUE" or "FALSE". I dont have any arrest rate column. What should I put in y in my case?
– S002
Dec 29 '18 at 18:45












Then you need to define an arrest rate calculation. It won’t just appear. What do you define as arrest rate? Will it be [# records where Arrest = True] / [# records]?
– sastrup
Dec 29 '18 at 18:50




Then you need to define an arrest rate calculation. It won’t just appear. What do you define as arrest rate? Will it be [# records where Arrest = True] / [# records]?
– sastrup
Dec 29 '18 at 18:50


















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.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • 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%2f53949144%2fhow-to-plot-arrest-rate-for-the-top-20-crime-types-crimes-of-chicago-datase%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

Angular Downloading a file using contenturl with Basic Authentication

Olmecas

Can't read property showImagePicker of undefined in react native iOS