本文介绍了R:ggplot2 barplot和错误栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 自ggplot2(0.9.3)的新版本以来,我有问题使用错误条来绘制条形图。所以我有一个这样的数据框: group N val sd se ci 1 206 3 37.2269533 7.9688645 4.6008261 19.7957568 2 207 3 2.0731505 2.2843009 1.3188417 5.6745180 3 208 3 2.2965978 1.4120606 0.8152536 3.5077531 4 209 3 3.1085132 1.1986664 0.6920504 2.9776525 5 210 3 3.3735251 1.9226134 1.1100214 4.7760365 6 211 3 4.0477951 2.9410503 1.6980162 7.3059739 7 212 3 1.2391158 1.2345554 0.7127709 3.0668055 8 213 2 1.3082374 1.1234220 0.7943793 10.0935460 我想为每个小组绘制val + - s:我在升级前做过: ggplot (dfc,aes(x = factor(group),y = factor(val))+ geom_bar(position = position_dodge())+ geom_errorbar(aes(ymin = val-se,ymax = val + se),width = .1 ,position = position_dodge(.9)) 它给了我: 映射变量t您也可以使用stat =bin。 当stat =bin时,它会尝试将y值设置为每个组中的个案数。 这可能会导致意外的行为,并且不会在未来版本的ggplot2中被允许。 如果您希望y表示个案的计数,则使用stat =bin并且不要将变量映射到y。 如果您希望y表示数据中的值,请使用stat =identity。 请参阅?geom_bar以获取示例。 (已弃用;上次在0.9.2版本中使用) 所以任何人都知道如何解决这个问题?谢谢 N。 $ b 解决方案 $ b my.df 206 3 37.2269533 7.9688645 4.6008261 19.7957568 207 3 2.0731505 2.2843009 1.3188417 5.6745180 208 3 2.2965978 1.4120606 0.8152536 3.5077531 209 3 3.1085132 1.1986664 0.6920504 2.9776525 210 3 3.3735251 1.9226134 1.1100214 4.7760365 211 3 4.0477951 2.9410503 1.6980162 7.3059739 212 3 1.2391158 1.2345554 0.7127709 3.0668055 213 2 1.3082374 1.1234220 0.7943793 10.0935460,header = TRUE) ggplot(my.df,aes(x = factor(group),y = val) )+ geom_bar(position = position_dodge())+ geom_errorbar(aes(ymin = val-se,ymax = val + se)) Since the new version of ggplot2 (0.9.3), I've problem to plot barplots with errorbars. So I've a dataframe like this : group N val sd se ci1 206 3 37.2269533 7.9688645 4.6008261 19.79575682 207 3 2.0731505 2.2843009 1.3188417 5.67451803 208 3 2.2965978 1.4120606 0.8152536 3.50775314 209 3 3.1085132 1.1986664 0.6920504 2.97765255 210 3 3.3735251 1.9226134 1.1100214 4.77603656 211 3 4.0477951 2.9410503 1.6980162 7.30597397 212 3 1.2391158 1.2345554 0.7127709 3.06680558 213 2 1.3082374 1.1234220 0.7943793 10.0935460I want to plot for each group the val +- s : I did that before upgrade :ggplot(dfc, aes(x=factor(group), y=factor(val)) + geom_bar(position=position_dodge()) + geom_errorbar(aes(ymin=val-se, ymax=val+se),width=.1,position=position_dodge(.9))It gives me that:Mapping a variable to y and also using stat="bin". With stat="bin", it will attempt to set the y value to the count of cases in each group. This can result in unexpected behavior and will not be allowed in a future version of ggplot2. If you want y to represent counts of cases, use stat="bin" and don't map a variable to y. If you want y to represent values in the data, use stat="identity". See ?geom_bar for examples. (Deprecated; last used in version 0.9.2)So anyone knows how to resolve that ? ThanksN. 解决方案 Is this what you're after?my.df <- read.table(text = "group N val sd se ci206 3 37.2269533 7.9688645 4.6008261 19.7957568207 3 2.0731505 2.2843009 1.3188417 5.6745180208 3 2.2965978 1.4120606 0.8152536 3.5077531209 3 3.1085132 1.1986664 0.6920504 2.9776525210 3 3.3735251 1.9226134 1.1100214 4.7760365211 3 4.0477951 2.9410503 1.6980162 7.3059739212 3 1.2391158 1.2345554 0.7127709 3.0668055213 2 1.3082374 1.1234220 0.7943793 10.0935460", header = TRUE)ggplot(my.df, aes(x = factor(group), y = val)) + geom_bar(position = position_dodge()) + geom_errorbar(aes(ymin=val-se, ymax=val+se)) 这篇关于R:ggplot2 barplot和错误栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-20 12:24