2011-11-08 18 views

Odpowiedz

9

Zastosowanie ggplot i tworzyć oddzielne warstwy:

library(ggplot2) 

set.seed(1) 
stupid <- data.frame(
    group= LETTERS[1:5], 
    men = sample(1:10, 5), 
    women = sample(1:10, 5) 
) 

# Melt the data and calculate totals 
mstupid <- melt(stupid, id.vars="group") 
stupidTotal <- ddply(mstupid, .(group), summarize, value=sum(value)) 

ggplot() + 
    geom_bar(data=stupidTotal, aes(x=group, y=value), fill="grey50") + 
    geom_bar(data=mstupid, aes(x=group, y=value, fill=variable), 
      stat="identity", position="dodge") + 
    theme_bw() 

enter image description here

1

Poszukaj 'barNest' w pakiecie plotrix

0

Użyj tego:

ggplot() + 
    geom_bar(data=stupidTotal, aes(x=group, y=value, fill="grey50"), stat="identity") + 
    geom_bar(data=mstupid, aes(x=group, y=value, fill=variable), 
      stat="identity", position="dodge") + 
    theme_bw() 
Powiązane problemy