KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
dodged bar plot in ggplot again has me stumped. I asked about annotating text above bars on here a few weeks back ( LINK ) and got a terrific response to use + stat_bin(geom="text", aes(label=..count.., vjust=-1)) . I figured since I already have the counts I'll just supply them with out the .. before and after and I told stat_bin that the position was dodge . It lines them up over the center of the group and adjusts up and down. Probably something minor. Please help me to get the text over the bars. mtcars2 <- data.frame(type=factor(mtcars$cyl), group=factor(mtcars$gear)) library(plyr); library(ggplot) dat <- rbind(ddply(mtcars2,.(type,group), summarise, count = length(group)),c(8,4,NA)) p2 <- ggplot(dat,aes(x = type,y = count,fill = group)) + geom_bar(colour = "black",position = "dodge",stat = "identity") + stat_bin(geom="text", aes(position='dodge', label=count, vjust=-.6))
Tags (comma-separated)
Save Edits
Cancel