数据:
df <- data.frame(
type = c("T", "F", "P", "T", "F", "P", "T", "F", "P", "T", "F", "P"),
size = c("50%", "50%", "50%", "100%", "100%", "100%", "150%", "150%", "150%", "200%", "200%", "200%"),
amount = c(48.4, 48.1, 46.8, 25.9, 26, 24.9, 21.1, 21.4, 20.1, 20.8, 21.5, 16.5)
)
我需要使用ggplot(x轴-> type
,y轴-> amount
,分组依据size
)绘制上述数据的条形图。当我使用以下代码时,我没有得到变量type
以及size
数据中显示的顺序。请看下图。我为此使用了以下代码。
ggplot(df, aes(type, amount , fill=type, group=type, shape=type, facets=size)) +
geom_bar(width=0.5, position = position_dodge(width=0.6)) +
facet_grid(.~size) +
theme_bw() +
scale_fill_manual(values = c("darkblue","steelblue1","steelblue4"),
labels = c("T", "F", "P"))
。
为了解决订单问题,我对变量“类型”使用了因子方法,并使用了以下方法。还请参见该图。
temp$new = factor(temp$type, levels=c("T","F","P"), labels=c("T","F","P"))
但是,现在我不知道如何确定变量的顺序size
。应该是50%,100%。150%和200%。