R 如何在条形图中包含具有NA观测值的类别级别
我想在R中显示一个图,显示一些我们没有收到任何数据的区域。因此,我希望/需要在没有可用数据的绘图中显示这些区域,以便我们可以在报告中显示我们没有收到的信息。我已经在Excel中完成了这项工作(见附件),并希望在R中完成 下面,查找我在R中开始执行的代码,但运行时显示错误:R 如何在条形图中包含具有NA观测值的类别级别,r,R,我想在R中显示一个图,显示一些我们没有收到任何数据的区域。因此,我希望/需要在没有可用数据的绘图中显示这些区域,以便我们可以在报告中显示我们没有收到的信息。我已经在Excel中完成了这项工作(见附件),并希望在R中完成 下面,查找我在R中开始执行的代码,但运行时显示错误: lags = c(15, 24, 34, 44,54,64,68,70,72,74,76,78) hf = c(2.56,2.16,4.23,0.00,2.73,
lags = c(15, 24, 34, 44,54,64,68,70,72,74,76,78)
hf = c(2.56,2.16,4.23,0.00,2.73,,,,10.81,3.13,16.67,10.34)
district = c(2.56,2.16,21.69,0.00,2.73,,,,10.81,2.34,33.33,7.76)
province = c(2.56,2.16,21.69,0.00,2.73,,,,10.81,2.34,33.33,7.76)
deviation = matrix(c(hf,district,province), nrow=length(lags), ncol=3,
dimnames=list(lags, c("hf","district","province")))
# Create a matrix deviation with the data
deviation1 = t(deviation) # Transpose the deviation matrix
#par(mfrow = c(1, 1)) # Open a new window for the plot
par(las=1,cex.axis=0.9,cex=0.9,cex.lab=0.9,cex.main=0.9,lwd=1)
bp2 <- barplot(deviation1, # Data (bar heights) to plot
beside=TRUE, # Plot the bars beside one another; default is to plot stacked bars
space=c(0.2,0.8), # Amount of space between i) bars within a group, ii) bars between groups
names.arg=c("Prov1", "Prov2", "Prov3", "Prov4", "Prov5","Prov6","Prov7", "Prov8", "Prov9", "Prov10",
"Prov11", "Prov12"), #Names for the bars
col=c("yellow4","orange1","darkred"), # Color of the bars
border="black", # Color of the bar borders
main=c(""), # Main title for the plot Método utilizado
xlab="", # X-axis label
ylab="", # Y-axis label
font.lab=2, ylim=c(0,100)) # Font to use for the axis labels: 1=plain text, 2=bold, 3=italic, 4=bold italic
legend("topleft", # Add a legend to the plot
legend=c("Health Facility","District","Province"), # Text for the legend
fill=c("yellow4","orange1","darkred"),bty = "n", cex=0.8) # Fill for boxes of the legend
text(x=bp2,2,y=c(deviation1[1:36]),labels=c(deviation1[1:36]),cex=0.8,pos=3)
Error in c(2.56, 2.16, 4.23, 0, 2.73, , , , 10.81, 3.13, 16.67, 10.34) :
argument 6 is empty
lags=c(15,24,34,44,54,64,68,70,72,74,76,78)
hf=c(2.56,2.16,4.23,0.00,2.73,10.81,3.13,16.67,10.34)
地区=c(2.56,2.16,21.69,0.00,2.73,10.81,2.34,33.33,7.76)
省=c(2.56,2.16,21.69,0.00,2.73,10.81,2.34,33.33,7.76)
偏差=矩阵(c(hf,地区,省),nrow=长度(滞后),ncol=3,
dimnames=列表(滞后、c(“高频”、“地区”、“省”))
#使用数据创建矩阵偏差
偏差1=t(偏差)#将偏差矩阵转置
#par(mfrow=c(1,1))#为绘图打开一个新窗口
par(las=1,cex.axis=0.9,cex=0.9,cex.lab=0.9,cex.main=0.9,lwd=1)
bp2该错误只是因为读取了您的数据。将间隙更改为NAs-例如hf=c(2.56,2.16,4.23,0.00,2.73,NA,NA,NA,10.81,3.13,16.67,10.34)
谢谢安德鲁!现在它开始工作了。