7
我有這樣的數據:超過1顏色geom_text()
data <- structure(list(Cod.projeto = c(7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L
), Nome.projeto = c("ESCOLAS INFANTIS", "ESCOLAS INFANTIS", "ESCOLAS INFANTIS",
"ESCOLAS INFANTIS", "ESCOLAS INFANTIS", "ESCOLAS INFANTIS", "ESCOLAS INFANTIS",
"ESCOLAS INFANTIS"), Secretarua = c("SMED", "SMED", "SMED", "SMED",
"SMED", "SMED", "SMED", "SMED"), Comp = structure(c(1L, 2L, 1L,
2L, 1L, 2L, 1L, 2L), .Label = c("28/02/2013", "01/03/2013"), class = c("ordered",
"factor")), Estado = c("Criadas", "Criadas", "Providas", "Providas",
"Criadas", "Criadas", "Providas", "Providas"), Categoria = c("A/G",
"A/G", "A/G", "A/G", "B", "B", "B", "B"), Vagas = c(67, 67, 63,
63, 124, 124, 73, 72)), .Names = c("Cod.projeto", "Nome.projeto",
"Secretarua", "Comp", "Estado", "Categoria", "Vagas"), row.names = c(NA,
-8L), class = "data.frame")
這ggplot2()
barplot:
require(ggplot2)
ggplot(data, aes(x=Categoria, y=Vagas, fill=relevel(factor(Estado),'Providas'))) +
geom_bar(position='dodge', stat='identity') +
ggtitle(substitute(atop(titulo, atop(subtitulo)),list(titulo=paste(data[1,1:2],collapse=' - '),subtitulo=data[1,3]))) +
theme(legend.position = "bottom") +
xlab("Categoria") +
ylab("Vagas") +
scale_fill_grey('') +
theme(panel.background = element_rect(fill='white'),panel.grid.major = element_line(colour = "gray70", linetype = 2)) +
geom_text(aes(x=Categoria, y=Vagas/2, label = sprintf("%1.0f", Vagas)),position = position_dodge(height=1,width=1), size=4, colour='white') +
facet_wrap(~ Comp)
結果造成:
我想要的變化德顏色文本只在ligth灰色列(Categoria = Criadas)。我已經嘗試在colour
參數中使用兩個值,但它不起作用。我所做的最接近的結果是當我在aes()
的內部添加colour=relevel(factor(Estado),'Providas'))
,但文本是粉紅色和藍色,並添加了一個我不想要的新圖例。
Didzis的編輯效果更好。 – Arun 2013-03-04 20:27:25