Tôi tạo ra bộ dữ liệu của riêng tôi để chứng minh làm thế nào để làm điều đó:
dữ liệu:
x <- runif(12,1,1.5)
y <- runif(12,1,1.5)
z <- runif(12,1,1.5)
m <- letters[1:12]
df <- data.frame(x,y,z,m)
Giải pháp:
#first of all you need to melt your data.frame
library(reshape2)
#when you melt essentially you create only one column with the value
#and one column with the variable i.e. your x,y,z
df <- melt(df, id.vars='m')
#ggplot it. x axis will be m, y will be the value and fill will be
#essentially your x,y,z
library(ggplot2)
ggplot(df, aes(x=m, y=value, fill=variable)) + geom_bar(stat='identity')
Output:
Nếu bạn muốn các thanh một cạnh khác mà bạn cần phải xác định vị trí dodge
tại geom_bar
ví dụ:
ggplot(df, aes(x=m, y=value, fill=variable)) +
geom_bar(stat='identity', position='dodge')
Bạn có thể cung cấp một số dữ liệu có thể tái sản xuất để chứng minh những gì bạn muốn hoàn thành? – cdeterman
Vui lòng bao gồm [ví dụ có thể tái sản xuất] (http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) với dữ liệu nhập mẫu và hiển thị bất kỳ mã nào bạn đã viết xa. – MrFlick
Xin lỗi, nó đã không được tải lên lúc đầu, tôi có một số vấn đề với các bức ảnh –