[英]R studio - stacked bar chart in R
我有一個看起來像這樣的數據框:
Name F R L M
1 1 564.4745 3.267577 3.056806 878.4101
2 2 593.6801 4.848597 2.507691 1450.8099
3 3 117.3233 6.819547 2.673681 1151.8267
4 Avg 776.4827 4.878574 2.746059 1160.6822
我想要一個所有變量的堆積條形圖(F,R,L,M),但到目前為止我只能在一個圖表中設置單個條形圖。 請幫忙
ggplot(Test.tibble, aes(x = Name, y = F, fill = Name)) +
geom_bar(stat = "identity") +
xlab("Name") +
ylab("Total") +
guides(fill = FALSE) +
theme_bw()
在base R
中,我們可以使用barplot
barplot(`colnames<-`(t(df1[-1]), df1[[1]]), legend = TRUE,
col = c('blue', 'green', 'red', 'yellow'))
df1 <- structure(list(Name = c("1", "2", "3", "Avg"), F = c(564.4745,
593.6801, 117.3233, 776.4827), R = c(3.267577, 4.848597, 6.819547,
4.878574), L = c(3.056806, 2.507691, 2.673681, 2.746059), M = c(878.4101,
1450.8099, 1151.8267, 1160.6822)), class = "data.frame", row.names = c("1",
"2", "3", "4"))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.