我正在做一个水平点图(?)ggplot2
,它让我考虑尝试创建一个水平条形图。但是,我发现能够做到这一点有一些限制。
这是我的数据:
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)
最初,我使用以下代码生成了一个点图:
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))
但是,我现在正在尝试创建一个水平条形图并发现我无法这样做。我试过coord_flip()
了,这也没有帮助。
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))
任何人都可以就如何在中生成水平条形图提供一些帮助ggplot2
吗?