答案 0 :(得分:4)
这应该没问题
#your data.frame
df <- read.table(text=
"col1 col2 col3 col4
Y N N N
Y N Y Y
Y N N Y
Y N N N", header=T)
library(reshape2)
df$ID <- 1:length(df)
df <- melt(df, id.vars = "ID") #melting the data.frame into long format
library(ggplot2) #and ploting it
ggplot(df)+
geom_bar(aes(x=variable, fill=value), stat="count")
对于百分比的结果,你可以做
ggplot(df) +
geom_bar(aes(x=variable, y= (..count..)/sum(..count..), fill=value))