r - Attempting barplot -
hi trying create beside barplot bars not in correct spaces appear overlapping.
barplot(counts, main ="2011 vs 2016 men volunteering", ylim=c(0,320000), xlab="age (years)", ylab = "frequancy", names.arg = c("15-19", "20-24", "25-34", "35-44", "45-54", "55-64", "65-74", "75-84", "84 , over"), col=c("red","green"), beside=true) legend("topright", legend = c("2011", "2016"), fill = c("red", "green"))
outputting this:
when in reality want this:
i have tried using ncol = 2 can't work, how implement it?
like this,
barplot(counts, main ="2011 vs 2016 men volunteering", ylim=c(0,320000), xlab="age (years)", ylab = "frequancy", names.arg = c("15-19", "20-24", "25-34", "35-44", "45-54", "55-64", "65-74", "75-84", "84 , over"), ncol = 2, col=c("red","green"), beside=true) legend("topright", legend = c("2011", "2016"), fill = c("red", "green"))
or this?
counts <- as.matrix(elevenmenvolunteerage, sixteenmenvolunteerage, ncol = 2)
all appreciated thank much.
as there no reproducible data counts
, including few examples on how dodged plots can created.
ggplot(mtcars, aes(factor(cyl), fill = factor(vs))) + geom_bar(position = "dodge")
# grouped bar plot counts <- table(mtcars$vs, mtcars$gear) barplot(counts, col=c("darkblue","red"), legend = rownames(counts), beside=true)
Comments
Post a Comment