Open rougerbaptiste opened 5 years ago
Look where it bugs because NA are already taken into account in plot_descriptive_data
on commun_fonctions
for barplot:
if(plot_type == "barplot") {
if(is.null(in_col)) {
mm2 = plyr::ddply(d, "x_axis", summarise, mean = mean(variable, na.rm = TRUE), sd = sd(variable, na.rm = TRUE))
p = ggplot(mm2, aes(x = x_axis, y = mean)) + geom_bar(stat = "identity")
limits <- aes(ymax = mean + sd, ymin = mean - sd)
p = p + geom_errorbar(limits, position = position_dodge(width=0.9), width=0.25)
} else {
d$toto = paste(d$in_col, d$x_axis, sep = "azerty")
mm = ddply(d, "toto", summarise, mean = mean(variable, na.rm = TRUE), sd = sd(variable, na.rm = TRUE))
mm$in_col = as.factor(sapply(mm$toto, function(x){unlist(strsplit(x, "azerty"))[1]}))
mm$x_axis = as.factor(sapply(mm$toto, function(x){unlist(strsplit(x, "azerty"))[2]}))
p = ggplot(mm, aes(x = x_axis, y = mean, fill = in_col))
p = p + geom_bar(position = "dodge", stat = "identity")
limits <- aes(ymax = mean + sd, ymin = mean - sd)
p = p + geom_errorbar(limits, position = position_dodge(width=0.9), width=0.25)
}
}
link with #98 ?
code to test ?
col_to_delete_because_only_NA = colnames(data_agro)[unlist(lapply(apply(data_agro, 2, function(x) {unique(is.na(x))}), function(x){x = sort(x);x[1]==TRUE}))]
data_agro = droplevels(data_agro[,!is.element(colnames(data_agro), col_to_delete_because_only_NA)])
NAs introduce error in a lot of common functions in R, thus should be removed from data after the tested variable is known.
test done with descriptive plot(data_agro, data_version) and barplot