業餘R用戶在這裏。我在網上看起來很難,看看這個問題是否已被回答/詢問,但我還沒有找到一個好的答案。我無法發佈圖片,因爲我沒有10個「聲望」在數據框中按因子排序堆積條形圖
我想要一個堆積條形圖,它根據攝取路線的貢獻百分比(按降序)對x變量進行排序。
Percent<-c(0.4,0.75,0.8, 0.3,0.1,0.6,0.25,0.5)
Inh<-data.frame(ID=c(rep(1,4),rep(2,4)),Age=factor(rep(1:4,2), label=c("0-1 year", "1-2 years", "2-3 years","3-6 years")), Route=factor(rep(1), label="Inhalation"), Percent=Percent)
Ing<-data.frame(ID=c(rep(1,4),rep(2,4)),Age=factor(rep(1:4,2), label=c("0-1 year", "1-2 years", "2-3 years","3-6 years")), Route=factor(rep(1), label="Ingestion"), Percent=1-Percent)
df<-data.frame(rbind(Inh,Ing))
ggplot(df,aes(x=ID,y=Percent,fill=Route))+ geom_bar(stat="identity")+
facet_wrap(~Age, scales = "free_x") +
ylab("Percent Contribution") +
labs(title = "Route Contribution to Exposure by Age Groups")
但我希望它看起來像這樣,我手動嘲笑了:
Percent<-c(0.1,0.6,0.25, 0.3,0.4,0.75,0.8,0.5)
Inh<-data.frame(ID=c(rep(1,4),rep(2,4)),Age=factor(rep(1:4,2), label=c("0-1 year", "1-2 years", "2-3 years","3-6 years")), Route=factor(rep(1), label="Inhalation"), Percent=Percent)
Ing<-data.frame(ID=c(rep(1,4),rep(2,4)),Age=factor(rep(1:4,2), label=c("0-1 year", "1-2 years", "2-3 years","3-6 years")), Route=factor(rep(1), label="Ingestion"), Percent=1-Percent)
df<-data.frame(rbind(Inh,Ing))
ggplot(df,aes(x=ID,y=Percent,fill=Route))+ geom_bar(stat="identity")+
facet_wrap(~Age, scales = "free_x") +
ylab("Percent Contribution") +
labs(title = "Route Contribution to Exposure by Age Groups")
預先感謝您!
更新:感謝羅蘭,我有一個情節!雖然問題仍然清晰。對於那些有興趣在這裏的代碼和最終產品:
ggplot(df,aes(x=id2,y=Percent,fill=Route, width=1,order = -as.numeric(Route)))+
geom_bar(stat="identity")+
facet_wrap(~Age, scales = "free_x") +
xlab(" ")+
ylab("Percent Contribution") +
theme(axis.text.x = element_blank(), axis.ticks.x= element_blank()) +
labs(title = "DEHP Route Contribution to Exposure by Age Groups")
對於圖片,你可以把它作爲鏈接,並有更高的聲譽的人可以添加它。 – agstudy
在線放置圖像或圖像:即您的輸入提供給您的圖像和模擬您希望產生的圖像。 –