0
我想生成一个条形图与ggplot2其中一个单一的酒吧是用指定的颜色分离。ggplot使用geom_bar - 区分单色条与颜色
要使用一个简单的数据帧说明:
type <- c('apples','pears','bananas','plums','melons','pineapples')
weight <- c(14,11,19,16,12,8)
fruit <- data.frame(type,weight)
这是我迄今为止生产的情节:
library("ggplot2")
f <- ggplot(fruit, aes(x=type, y=weight))
f + geom_bar(stat=’identity", fill = (ifelse(fruit$type=='bananas', 'yellow', 'gray')))
OK,所以有什么问题呢? (除了你的''',而不是''') – Axeman
我得到'甜瓜'填充为黄色时,它应该是'香蕉' – Curious56
好吧。尝试'f + geom_col(aes(fill = ifelse(fruit $ type =='bananas','yellow','gray')))+ scale_fill_identity()' – Axeman