I was trying to make bars in clustered column plot appearing with a decreasing ordered based on values of y axis(pososto).I tryed aes(x=reorder(allele,-pososto,sum(and mean)) but those didn't work.If someone can help it would be perfect. Thank you in advance!
Part of my data:
df <- structure(list(allele = c("Ak24:02", "Ak24:02", "Ak24:02", "Ak24:02",
"Ak02:01", "Ak02:01", "Ak02:01", "Ak02:01", "Ak01:01", "Ak01:01",
"Ak01:01", "Ak01:01", "Ak11:01", "Ak11:01", "Ak11:01", "Ak11:01",
"Ak03:01", "Ak03:01", "Ak03:01", "Ak03:01", "Ak32:01", "Ak32:01",
"Ak32:01", "Ak32:01", "Ak26:01", "Ak26:01"), subject = c("her",
"reth", "las", "xan", "her", "reth", "las", "xan", "her", "reth",
"las", "xan", "her", "reth", "las", "xan", "her", "reth", "las",
"xan", "her", "reth", "las", "xan", "her", "reth"), pososto = c(6.2076749,
0, 14.3529412, 0, -0.7751938, 0, -0.7751938, 0, 5.0666604, 0,
0, 11.944798, 0, 0, 9.7559913, 6.0631187, -12.4022258, -1.3476446,
13.1983584, 17.1626014, 0, -13.1511297, 14.7583726, -5.6592186,
0, 0)), class = "data.frame", row.names = c("1", "2", "3", "4",
"5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15",
"16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26"
))
My basic code:
df = data.frame(allele, subject, pososto)
df$subject <- factor(df$subject, levels =c("her", "xan", "las", "reth"))
df$pososto = as.numeric(df$pososto)
p=ggplot(df, aes(x = allele, y = pososto, fill = subject)) +
geom_bar(position = "dodge",stat = "identity", aes(fill= subject)) +
#gia labels
# geom_text(aes(label = round(count, 2)),position = position_dodge(width = 0.9),
# vjust = ifelse(df[,3]>=0, -0.5, 1) , size= 3)+
scale_x_discrete(limits = (unique(df$allele))) +
scale_fill_manual(values=c("#696969","#778899","#A9A9A9","#CCCCFF"))+
theme_bw(base_size = 9) +
geom_hline(yintercept = 0, colour = "black") +
theme(axis.text.x = element_text(angle = 60, hjust = 1))strong text`
dataframe is looking like this:
The plot I am taking from basic code: