我用ggplot2创建了一个图表,我有这个代码,它运行得很好。
ggp <- ggplot(data.frame(diam.split.data$"(0,10]"),aes(x=intcat))
ggp + geom_bar() +
geom_text(stat='count', aes(label=paste(round(..count../151*100),"%")), vjust=-1)
但是,每次创建不同的图表时,我都需要手动更改151(此数据集的总观察值)。所以我想出了这一行,它给了我151(也适用于每个不同的数据集):
f1 <- (as.numeric(substr(((unname((summary(diam.split.data$"(0,10]"))))[1,1]),
start=9, stop=20)))
这里没问题。 f1以与f1 < - 151相同的方式给出151。
但是当我尝试用ggplot2代码替换151时,它失败了:
粘贴错误(公式=圆形(计数/ f1 * 100),“%”):未找到对象'f1'
如何告诉R使用f1作为标准数值(与151一样)?
答案 0 :(得分:0)
我的问题的解决方案是将((.count ..)/ sum(.. count ..)* 100)替换为(..count ../ 151 * 100)为@ R.S。建议。谢谢大家。