數(shù)據(jù):type size amount T 50% 48.4 F 50% 48.1 P 50% 46.8 T 100% 25.9 F 100% 26.0 P 100% 24.9 T 150% 21.1 F 150% 21.4 P 150% 20.1 T 200% 20.8 F 200% 21.5 P 200% 16.5我需要使用ggplot繪制上述數(shù)據(jù)的條形圖(x軸->“類型”,y軸->“數(shù)量”,按“大小”分組)。當(dāng)我使用以下代碼時(shí),沒(méi)有按數(shù)據(jù)中顯示的順序獲取變量“ type”和“ size”。請(qǐng)看下圖。我為此使用了以下代碼。 ggplot(temp, 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"))為了解決訂單問(wèn)題,我對(duì)變量“類型”使用了因子方法,并使用了以下方法。也請(qǐng)參見(jiàn)該圖。temp$new = factor(temp$type, levels=c("T","F","P"), labels=c("T","F","P")) 但是,現(xiàn)在我不知道如何確定變量“ size”的順序。應(yīng)該是50%,100%。150%和200%。
固定ggplot中的構(gòu)面順序
慕無(wú)忌1623718
2019-11-28 09:56:23