我有这个数据框
dput(C_Em_2000_Lat_Am)
structure(list(V1 = structure(c(4L, 3L, 5L, 6L, 1L, 2L, 7L, 8L
), .Label = c("Crop Agriculture", "Mining", "Mixed Agriculture",
"Other land use", "Pasture", "Tree crops", "Urban", "Water"), class = "factor"),
V2 = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "Emission Factor", class = "factor"),
V3 = c(97004.1719086906, 10899.1747511239, 938738.864637841,
11024.7872260286, 129805.568347205, 778.178352715695, 28603.3785457348,
24333.5577048119)), .Names = c("V1", "V2", "V3"), row.names = c(NA,
-8L), class = "data.frame")
我想绘制列V3的百分比值,它们是当前的绝对值。到目前为止,我已设法绘制绝对值(见下文),但也需要绘制每个值的百分比(其中总值= V3列中值的总和)。
ggplot(C_Em_2000_Lat_Am, aes(x=V1, y = V3)) + geom_histogram(stat="identity", binwidth = 0.1)+
labs(x = "", y = "Carbon Emissions (T/year)") +
theme(axis.text=element_text(size=16),axis.title=element_text(size=20),
legend.title=element_text(size=20, face='bold'),legend.text=element_text(size=20), axis.line = element_line(colour = "black")) +
scale_fill_grey("grey50") + scale_y_continuous(limits=c(0,1000000))
有人可以帮我解决这个问题吗?感谢
答案 0 :(得分:0)
这是答案。
ggplot(C_Em_2000_Lat_Am, aes(x=C_Em_2000_Lat_Am$V1, y = (C_Em_2000_Lat_Am$V3)/sum(C_Em_2000_Lat_Am$V3))) + geom_bar(stat="identity")+
scale_y_continuous(labels = percent_format(), limits=c(0,1))+
labs(x = "", y = "Carbon Emissions (%)") +
theme(axis.text=element_text(size=16),axis.title=element_text(size=20),
legend.title=element_text(size=20, face='bold'),legend.text=element_text(size=20), axis.line = element_line(colour = "black")) + scale_fill_grey("grey50")