geom-bar
How to add frequency count labels to the bars in a bar graph using ggplot2? [duplicate]
ggplot(data=diamonds, aes(x=clarity)) + geom_bar() + geom_text(stat=”count”, aes(label=..count..), vjust=-1)
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 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
customize ggplot2 axis labels with different colors
You can provide a vector of colors to the axis.text.x option of theme(): a <- ifelse(data$category == 0, “red”, “blue”) ggplot(data, aes(x = x, y = y)) + geom_bar(stat = “identity”, aes(fill = category)) + theme(axis.text.x = element_text(angle = 45, hjust = 1, colour = a))
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
ggplot bar plot with facet-dependent order of categories
Ok, so all philosophizing aside, and in case anyone is interested, here is an ugly hack to do it. The idea is to use different labels (think paste(period, name) except I replace the period into 0-space, 1-space, etc. so that they don’t show). I need this plot and I don’t want to arrange grobs and … Read more