在分类变量的图表中显示%而不是计数
ggplot
qplot(mydataf) + stat_bin(aes(n = nrow(mydataf), y = ..count../n)) + scale_y_continuous(formatter = "percent")
mydata <- c ("aa", "bb", NULL, "bb", "cc", "aa", "aa", "aa", "ee", NULL, "cc");mydataf <- factor(mydata);qplot (mydataf); #this shows the count, I'm looking to see % displayed.
ggplot
qplot
ggplot(mydataf, aes(y = (..count..)/sum(..count..))) + scale_y_continuous(formatter = 'percent');ggplot(mydataf, aes(y = (..count..)/sum(..count..))) + scale_y_continuous(formatter = 'percent') + geom_bar();ggplot(mydataf, aes(x = levels(mydataf), y = (..count..)/sum(..count..))) + scale_y_continuous(formatter = 'percent');ggplot(mydataf, aes(x = levels(mydataf), y = (..count..)/sum(..count..))) + scale_y_continuous(formatter = 'percent') + geom_bar();
Error: ggplot2 doesn't know how to deal with data of class factor
ggplot (data=mydataf, aes(levels(mydataf))) + geom_bar()
ggplot
MM们
蝴蝶刀刀
jeck猫