Horizontal Barplot dans ggplot2

Je travaillais sur l'horizontale dot plot (?) dans ggplot2, et il m'a fait penser à essayer de créer une horizontale barplot. Cependant, je trouve certaines limites dans le fait d'être capable de faire cela.

Voici mes données:

df <- data.frame(Seller=c("Ad","Rt","Ra","Mo","Ao","Do"), 
                Avg_Cost=c(5.30,3.72,2.91,2.64,1.17,1.10), Num=c(6:1))
df
str(df)

D'abord, j'ai généré un point de la parcelle en utilisant le code suivant:

require(ggplot2)
ggplot(df, aes(x=Avg_Cost, y=reorder(Seller,Num))) + 
    geom_point(colour="black",fill="lightgreen") + 
    opts(title="Avg Cost") +
    ylab("Region") + xlab("") + ylab("") + xlim(c(0,7)) +
    opts(plot.title = theme_text(face = "bold", size=15)) +
    opts(axis.text.y = theme_text(family = "sans", face = "bold", size = 12)) +
    opts(axis.text.x = theme_text(family = "sans", face = "bold", size = 12))

Cependant, je suis en train d'essayer de créer une horizontale barplot et de trouver que je suis incapable de le faire. J'ai essayé coord_flip() et qui n'a pas été très utile.

ggplot(df, aes(x=Avg_Cost, y=reorder(Seller,Num))) + 
    geom_bar(colour="black",fill="lightgreen") + 
    opts(title="Avg Cost") +
    ylab("Region") + xlab("") + ylab("") + xlim(c(0,7)) +
    opts(plot.title = theme_text(face = "bold", size=15)) +
    opts(axis.text.y = theme_text(family = "sans", face = "bold", size = 12)) +
    opts(axis.text.x = theme_text(family = "sans", face = "bold", size = 12)) 

Quelqu'un peut-il fournir une assistance sur la façon de générer une horizontale barplot dans ggplot2?

InformationsquelleAutor ATMathew | 2012-06-07