R ggplot-boxplot+;填充&x2B;彩色啤酒光谱

R ggplot-boxplot+;填充&x2B;彩色啤酒光谱,r,ggplot2,R,Ggplot2,我似乎无法使用color brewer用连续值填充箱线图,而且我知道这一定是某个地方语法的简单交换,因为我可以根据连续值获得要调整的箱线轮廓。以下是我正在处理的数据: data <- data.frame( value = sample(1:50), animals = sample(c("cat","dog","zebra"), 50, replace = TRUE), region = sample(c("forest","desert","tundra"),

我似乎无法使用color brewer用连续值填充箱线图,而且我知道这一定是某个地方语法的简单交换,因为我可以根据连续值获得要调整的箱线轮廓。以下是我正在处理的数据:

data <- data.frame(
    value = sample(1:50),
    animals = sample(c("cat","dog","zebra"), 50, replace = TRUE),
    region = sample(c("forest","desert","tundra"), 50, replace = TRUE)
)

data如果需要为箱线图设置填充,则使用
fill=animal
s代替
fill=animal
s,同样的方法将
scale\u color\u brewer()
替换为
scale\u fill\u brewer()

orderindex <- order(as.numeric(by(data$value, data$animals, median)))
data$animals <- ordered(data$animals, levels=levels(data$animals)[orderindex])
library(ggplot2)
first <- qplot(animals, value, data = data, colour=animals)
second <- first + geom_boxplot() + facet_grid(~region)
third <- second + scale_colour_brewer()
print(third)
second <- first + geom_boxplot(aes(scale_colour_brewer())) + facet_grid(~region)
qplot(animals, value, data = data, fill=animals)+ 
  geom_boxplot() + facet_grid(~region) + scale_fill_brewer()