ggplot2 and a Stacked Bar Chart with Negative Values

Update: As of ggplot2 2.2.0, stacking for negative values is handled automatically, without having to create separate layers for the positive and negative values. If I understand what you’re looking for, the trick is to put the two positive and negative data in separate layers, and also to use stat = “identity”: dat <- read.table(text … Read more

Change bar plot colour in geom_bar with ggplot2 in r

If you want all the bars to get the same color (fill), you can easily add it inside geom_bar. ggplot(data=df, aes(x=c1+c2/2, y=c3)) + geom_bar(stat=”identity”, width=c2, fill = “#FF6666”) Add fill = the_name_of_your_var inside aes to change the colors depending of the variable : c4 = c(“A”, “B”, “C”) df = cbind(df, c4) ggplot(data=df, aes(x=c1+c2/2, y=c3, … Read more

Stacked bar chart

You said : Maybe my data.frame is not in a good format? Yes this is true. Your data is in the wide format You need to put it in the long format. Generally speaking, long format is better for variables comparison. Using reshape2 for example , you do this using melt: dat.m <- melt(dat,id.vars = … Read more