How to plot arrest rate (%) for the top 20 crime types (crimes of chicago dataset)?
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
r plot highcharts summarize
|
show 3 more comments
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
r plot highcharts summarize
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 taggedggplot2
?
– camille
Dec 27 '18 at 18:52
|
show 3 more comments
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
r plot highcharts summarize
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
r plot highcharts summarize
r plot highcharts summarize
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 taggedggplot2
?
– camille
Dec 27 '18 at 18:52
|
show 3 more comments
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 taggedggplot2
?
– 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
|
show 3 more comments
1 Answer
1
active
oldest
votes
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.
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
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%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
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
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.
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.
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%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
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
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