带标准差的R柱状图

带标准差的R柱状图,r,standard-deviation,bar-chart,R,Standard Deviation,Bar Chart,我是一个新的R用户,在条形图中绘制一些数据时遇到困难。如果这真的很容易做到,请提前道歉,我就是想不出来。 我有六组数据:三组数据分别是1年、5年和10年时的1辆车数据,三组数据分别是1年、5年和10年时的2辆车数据,其中每辆车在每个年龄段的测量值包括1)计算车外凹痕总数和2)去除油漆的凹痕数。我想做一个6条的箱线图,对应于每辆车及其各自的年龄,其中柱高是去除油漆的凹痕总数,带有标准偏差条。 以下是我迄今为止一直在尝试的内容(仅包括2个数据集): 我发现了一个错误条的例子:箭头(条,x,条,x+-

我是一个新的R用户,在条形图中绘制一些数据时遇到困难。如果这真的很容易做到,请提前道歉,我就是想不出来。 我有六组数据:三组数据分别是1年、5年和10年时的1辆车数据,三组数据分别是1年、5年和10年时的2辆车数据,其中每辆车在每个年龄段的测量值包括1)计算车外凹痕总数和2)去除油漆的凹痕数。我想做一个6条的箱线图,对应于每辆车及其各自的年龄,其中柱高是去除油漆的凹痕总数,带有标准偏差条。 以下是我迄今为止一直在尝试的内容(仅包括2个数据集):

我发现了一个错误条的例子:
箭头(条,x,条,x+-(stdv),长度=0.15,角度=90)
,但我无法将其用于我的数字。此外,在本例中,y轴在15处停止,但杆Car1Yr5在19处停止。如何绘制最大为20或30的y轴?
同样,我是R的新手,任何帮助都将不胜感激。我已经断断续续地试着解决这个问题大约两周了。谢谢。

我对你的数据有点困惑。。。从你的例子中,我假设1号车有101个凹痕没有去除油漆,9个凹痕没有去除油漆,2号车有131个凹痕没有去除油漆,19个凹痕没有去除油漆

现在计算凹痕数的标准偏差对我来说没有多大意义。。。您正在绘制计数数据,因此不应该有任何标准偏差,除非您有许多相同型号的汽车,并且希望看到汽车之间的变化

最好的方法是通过以下操作计算去除油漆的凹痕百分比:

car1yr1 = c(rep(0, 101), rep(1, 9)) #car has 9 dents that remove paint
car1yr5 = c(rep(0, 131), rep(1, 19)) #car has 19 dents that remove paint

# The total number of observations is the total number of dents
total.dents.1 <- length(car1yr1)
total.dents.5 <- length(car1yr5)
# The dents that remove paint are marked as 1, the others with 0, 
# so we can just sum all of the data to get the number of paint-removing dents
dents.paint.1 <- sum(car1yr1)
dents.paint.5 <- sum(car1yr5)
# Alternatively you can use
# dents.paint.1 <- length(which(car1yr1==1))
# Calculate the %
dents.paint.perc.1 <- dents.paint.1/total.dents.1
dents.paint.perc.5 <- dents.paint.1/total.dents.5

df <- data.frame(dents.paint.perc.1, dents.paint.perc.5)

# Plot the data. 
# ylim specifies the limits of the y axis
# ylab defines the axis title. 
# las=1 puts the labels on the y axis horizontally
# names defines the labels on the x axis
barplot(as.matrix(df)*100, ylim=c(0,20), 
        ylab="% dents removing paint", las=1,
        names=c("Car 1 year 1", "Car 1 year 5"))
car1yr1=c(rep(0,101),rep(1,9))#汽车有9个凹痕,可以去除油漆
car1yr5=c(代表(0131),代表(1,19))35;汽车有19个凹痕,可以去除油漆
#观察总数即凹痕总数

总数。凹痕。1我有点困惑-你想计算一辆车计数的标准偏差吗?您不应该使用该车所有凹痕的标准偏差来绘制每辆车的每个油漆去除凹痕的计数。
car1yr1 = c(rep(0, 101), rep(1, 9)) #car has 9 dents that remove paint
car1yr5 = c(rep(0, 131), rep(1, 19)) #car has 19 dents that remove paint

# The total number of observations is the total number of dents
total.dents.1 <- length(car1yr1)
total.dents.5 <- length(car1yr5)
# The dents that remove paint are marked as 1, the others with 0, 
# so we can just sum all of the data to get the number of paint-removing dents
dents.paint.1 <- sum(car1yr1)
dents.paint.5 <- sum(car1yr5)
# Alternatively you can use
# dents.paint.1 <- length(which(car1yr1==1))
# Calculate the %
dents.paint.perc.1 <- dents.paint.1/total.dents.1
dents.paint.perc.5 <- dents.paint.1/total.dents.5

df <- data.frame(dents.paint.perc.1, dents.paint.perc.5)

# Plot the data. 
# ylim specifies the limits of the y axis
# ylab defines the axis title. 
# las=1 puts the labels on the y axis horizontally
# names defines the labels on the x axis
barplot(as.matrix(df)*100, ylim=c(0,20), 
        ylab="% dents removing paint", las=1,
        names=c("Car 1 year 1", "Car 1 year 5"))