0

I want to make a graphic with the total positive cases of each city per year.

For example in Butte in 2006 there has been a total of (invented) 34 cases so I need this but with every city.

This is the data that I'm working with: enter image description here

zelite
  • 1,303
  • 15
  • 34
Brush
  • 21
  • 1
  • 1
    Does this answer your question? [Aggregate / summarize multiple variables per group (e.g. sum, mean)](https://stackoverflow.com/questions/9723208/aggregate-summarize-multiple-variables-per-group-e-g-sum-mean) – markus Feb 22 '20 at 12:05

2 Answers2

0

For example,

aggregate(Positive.Cases ~ Year + County, data=df, sum)

You have the documentation here : aggregate_function

Hope I was able to help you.

Julien Jm
  • 553
  • 6
  • 20
  • Oh thanks!!!!!! And how I implement that on a graphic? Sorry for being that annoying but I don't understand R at all – Brush Feb 22 '20 at 11:42
0
> aggregate(Positive.Cases ~ Year + County, FUN=sum, data=data)
  Year       County Positive.Cases
1 2006      Alameda             13
2 2006        Butte             93
3 2006 Contra Costa             40
4 2006       Coulsa             22

# Barplot
library(ggplot)
library(dplyr)

data %>%
  mutate(Year = factor(Year)) %>%
  group_by(Year, County) %>%
  summarise(Case=sum(Positive.Cases)) %>%
  ggplot(aes(Year, Case,fill=County)) +
  geom_bar(stat="identity", position="dodge")

enter image description here

Edward
  • 8,978
  • 2
  • 9
  • 24