I'm trying to get means for a quantitative variable, then plot means for this quant variable BY day of week (categorical)
Have tried reorganizing data and such, but to now avail.
Very simple but has me stumped. Thanks!
I'm trying to get means for a quantitative variable, then plot means for this quant variable BY day of week (categorical)
Have tried reorganizing data and such, but to now avail.
Very simple but has me stumped. Thanks!
general example: average income by day
library(data.table)
library(ggplot2)
setDT(data)
# get average income by day
temp <- data[, .(mean_income= mean(income, na.rm=T)), by = day]
# plot
ggplot(data=temp) +
geom_bar( aes(x=day, y= mean_income) , stat = "identity") +
labs(x="day of the week", y="average income")
how about:
library(dplyr)
x <- data.frame(day = rep(c("monday", "tuesday", "wednesday") ,3), val = runif(9))
x2 <- x %>%
group_by(day) %>%
summarise(mean = mean(val))
barplot(x2$mean, names.arg = x2$day)