0

I am very new to this and I wanted to add that the various ways in which I tried to reshape/melt the data. My data in three different variations:

Version 1:

year,type,total,action,perc
    2015,v,"1,199,310",crime,42.16 
    2015,p,"8,024,115",crime,18.24 
    2015,v,"505,681",arrest,42.16 
    2015,p,"1,463,213",arrest,18.24 
    2016,v,"1,250,162",crime,32.85 
    2016,p,"7,928,530",crime,17.07 
    2016,v,"410,717",arrest,32.85 
    2016,p,"1,353,283",arrest,17.07 
    2017,v,"1,247,321",crime,41.58 
    2017,p,"7,694,086",crime,16.24 
    2017,v,"518,617",arrest,41.58 
    2017,p,"1,249,757",arrest,16.24

Version 2:

year,type,crime,arrest,perc
    2015,1,"1,199,310","505,681",42.16 
    2015,2,"8,024,115","1,463,213",18.24 
    2016,1,"1,250,162","410,717",32.85 
    2016,2,"7,928,530","1,353,283",17.07 
    2017,1,"1,247,321","518,617",41.58 
    2017,2,"7,694,086","1,249,757",16.24 

Version 3:

df <- vpcrimetotal

    year,vcrime,varrest,varrestperc,pcrime,parrest,parrestperc
    2017,"1,247,321","518,617",0.4158,"7,694,086","1,249,757",0.1624
    2016,"1,250,162","410,717",0.3285,"7,928,530","1,353,283",0.1707
    2015,"1,199,310","505,681",0.4216,"8,024,115","1,463,213",0.1824

The idea is to show the total number of violent crime versus property crime from 1990-2017 with the number of arrests (labeled as a percent) inside each bar based on crime type (property or violent). The preference is to stack all four into one bar per year with different colors for each.

I found these that helped but was still confused in figuring out how to fit my data into them. how to create stacked bar charts for multiple variables with percentages, but to maybe look like this Count and Percent Together using Stack Bar in R

I have used these sets of data to the code but is probably confusing if I post all the different ones I tried that don't work.

Dan C.
  • 9
  • 2
  • 1
    Welcome to SO! Having an example of your dataset is a good start. Can you also show an example of what you want your final dataset to look like? Are you thinking you want one column for crime, one for arrest, and one for arrest percent along with a "grouping" column of "v" vs "p"? – aosmith Mar 15 '19 at 18:06
  • Thanks aosmith! I have tried so many ways to make the data long and work for me. I edited to reflect the other examples I have. – Dan C. Mar 15 '19 at 22:57
  • 1
    You may need to draw out your output even if you cannot render a partial. Also, what did you try? – Parfait Mar 17 '19 at 23:17

0 Answers0