library(ggplot2)
transp = c("bicycle", "bus", "bus", "walking", "bus", "bicycle", "bicycle", "bus")
dat1 = data.frame(transp)
library(forcats)
ggplot(data=dat1) + geom_bar(mapping=aes(x=fct_infreq(transp))) + xlab("Transportation")
obesity = factor(c("underweight", "normal", "overweight", "obese"),
levels=c("underweight", "normal", "overweight", "obese"))
count = c(6, 69, 27, 13)
perc = count / sum(count) * 100
dat2 = data.frame(obesity, count, perc)
ggplot(data=dat2) + geom_bar(mapping=aes(x=obesity, y=perc), stat="identity") + xlab("Obesity") + ylab("Percentage(%)")
table(transp)
dat3 = data.frame(transportation=c("bus", "bicycle", "walking"),
count=c(15, 13, 4))
Leave a comment