r - plot mean of a continuous variable by a categorical variable and group by a factor -
i'd think fundamental can't find how in introductory texts have nor googling. want plot mean of continuous variable categorical variable , group factor. continuous variable 'cd' (blood cd4 protein), categorical year (1 - 10 years), factor failure = 0 or 1. dataset 'f3'
i've used aggregate mean cd year, can't find how group failure (0,1) no , yes. prefer use ggplot.
the plot this:
ggplot(f3, aes(factor(year), mean(cd), color = factor(failure))) + geom_line() + geom_point(size=2)
is horizontal line or 2 lines overlaid, indicating group failure in legend. so, it's not plotting mean cd year, overall mean. please help.
data:
f3 <- structure(list(year = structure(c(6l, 7l, 8l, 9l, 10l, 1l, 2l, 3l, 4l, 5l, 6l), .label = c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10"), class = "factor"), cd = c(555l, 511l, 540l, 596l, 553l, 142l, 173l, 271l, 163l, 108l, 61l), failure = structure(c(1l, 1l, 1l, 1l, 1l, 2l, 2l, 2l, 2l, 2l, 2l), .label = c("0", "1"), class = "factor")), .names = c("year", "cd", "failure"), row.names = c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11"), class = "data.frame")
library(rcharts) x1 <- xplot(value ~ year, group = "failure", data = f3, type = "line-dotted") x1
Comments
Post a Comment