This is my whole code. I want to do a barplot of the days with the most infected and differentiate between the Group M and the group H
db<-read.csv(file = 'casos_hosp_uci_def_sexo_edad_provres.csv')
##############################################################
#Day of most infections
dbDate=data.frame(fecha = unique(db$fecha),
total = sapply(split(db, f = db$fecha), function(x) {sum(x[['num_casos']])}))
dbDateSort<-dbDate[order(dbDate$total, decreasing = T),]
#Most infections province A
dbSub <- db[db$provincia_iso == "A",]
dbSub<-na.omit(dbSub)
dbDateSub=data.frame(fecha = unique(dbSub$fecha),
total = sapply(split(dbSub, f = dbSub$fecha), function(x) {sum(x[['num_casos']])}))
dbDateSortSub<-dbDateSub[order(dbDateSub$total, decreasing = T),]
#Most infections in province A for days of most infections nationwide
dbDateSubSortNacional <-dbDateSub[order(match(dbDateSub[,1],dbDateSort[,1])),]
#Most infections for group H in province A for days of most infections nationwide
dbSubH<- db[db$provincia_iso == "A" & db$sexo=="H",]
dbSubH<-na.omit(dbSubH)
dbDateSubH=data.frame(fecha = unique(dbSubH$fecha),
total = sapply(split(dbSubH, f = dbSubH$fecha), function(x) {sum(x[['num_casos']])}))
dbDateSubHSortNacional <-dbDateSubH[order(match(dbDateSubH[,1],dbDateSort[,1])),]
#Most infections for group M in province A for days of most infections nationwide
dbSubM<- db[db$provincia_iso == "A" & db$sexo=="M",]
dbSubM<-na.omit(dbSubM)
dbDateSubM=data.frame(fecha = unique(dbSubM$fecha),
total = sapply(split(dbSubM, f = dbSubM$fecha), function(x) {sum(x[['num_casos']])}))
dbDateSubMSortNacional <-dbDateSubM[order(match(dbDateSubM[,1],dbDateSort[,1])),]
#Attempt to plot both gropus together
dbDateSubHSortNacional$set <- 'H'
dbDateSubMSortNacional$set <- 'M'
combined <- rbind(dbDateSubHSortNacional, dbDateSubMSortNacional)
combined_wide <- reshape(combined, direction = 'wide', idvar = 'set', timevar = 'fecha')
barplot(cbind(total.2022_01_10, total.2022_01_11, total.2022_01_04, total.2022_01_05, total.2022_01_12) ~ set, data = combined_wide, col = rainbow(5))
I think I have not explained myself very well. I want a plot of five bars, each one with two colours, representing M and H.