我想用條形圖內的百分比來做一個黑色條形圖。這可能來自qplot嗎?我得到的百分比出現,但他們不符合特定的酒吧。將標籤添加到ggplot條形圖
包:GGPLOT2,重塑
x <- data.frame(filename = c("file1", "file2", "file3", "file4"),
low = c(-.05,.06,.07,-.14),
hi = c(.87,.98,.56,.79))
x$tot <- x$hi + x$low
x <- melt(x, id = 'filename')
bar <- qplot(x = factor(filename),
y = value*100,
fill = factor(variable),
data = x,
geom = 'bar',
position = 'dodge') + coord_flip()
bar <- bar + scale_fill_manual(name = '',
labels = c('low',
'Hi',
"Tot"),
values = c('#40E0D0',
'#FF6347',
"#C7C7C7"))
bar <- bar + geom_text(aes(label = value*100))+geom_bar(colour = 'black')
bar <- bar + opts(panel.background = theme_rect(colour = NA))
bar <- bar + opts(legend.justification = 'bottom')
print(bar)
歡迎到SO。由於您使用的是非基本的R函數,因此請添加對重現代碼所需的包的引用,即'library(...)' – Andrie 2012-07-25 15:32:28