更新时间:2023-11-26 21:44:10
@baptiste指出,您应使用 aes_string()
而不是 aes()
来在定义中使用字符串x和y值。另外,您还应该在引号中放入值
和变量
。
As pointed out by @baptiste you should use aes_string()
instead of aes()
to use strings in defining x and y values. Also you should put value
and variable
inside quotes.
PropBarPlot<-function(df, mytitle=""){
melteddf<-melt(df, id=names(df)[1], na.rm=T)
ggplot(melteddf, aes_string(x=names(df)[1],y= "value", fill="variable")) +
geom_bar(position="fill") +
theme(axis.text.x = element_text(angle=90, vjust=1)) +
labs(title=mytitle)
}