Generate paired stacked bar charts in ggplot (using position_dodge only on some variables)

One workaround would be to put interaction of sample and name on x axis and then adjust the labels for the x axis. Problem is that bars are not put close to each other. ggplot(df, aes(x = as.numeric(interaction(sample,name)), y = count, fill = type)) + geom_bar(stat = “identity”,color=”white”) + scale_x_continuous(breaks=c(1.5,3.5,5.5),labels=c(“oak”,”birch”,”cedar”)) Another solution is to use … Read more

ggplot2 geom_bar – how to keep order of data.frame [duplicate]

Posting as answer because comment thread getting long. You have to specify the order by using the factor levels of the variable you map with aes(x=…) # lock in factor level order df$derma <- factor(df$derma, levels = df$derma) # plot ggplot(data=df, aes(x=derma, y=prevalence)) + geom_bar(stat=”identity”) + coord_flip() Result, same order as in df: # or, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)