-1

I have a data frame that looks like this

    TYPE              YEAR        
    ARSON             2008
    THEFT             2009  
    ARSON             2010
    ASSAULT           2008  

The data continue's with more types and the years are between 2008-2012. I am trying to create a ggplot2 graph that has the the years on the x, the count of the type on the y and muliple lines representing each type.

I've tried melting with multiple variables and couldn't figure it out

air bmx
  • 11
  • 1
  • 4
  • Try creating one of [these](https://stackoverflow.com/help/mcve) so that we can help you troubleshoot your code. – bob1 May 08 '19 at 18:35

1 Answers1

0

You don't need to use melt. Use table() or one of the many other ways to count frequencies.

library(ggplot2)
yourData <- data.frame(TYPE = c('ARSON', 'THEFT', 'ARSON', 'ASSAULT'),
                       YEAR = c('2008', '2009', '2010', '2008'))
plotData <- as.data.frame(table(yourData))
ggplot(plotData, aes(YEAR, Freq, group = TYPE, color = TYPE)) +
    geom_line()
Riley Finn
  • 918
  • 1
  • 7
  • 19