我在R.工作 我有几个barplot可以生产,我希望所有这些都有相同的x轴(xlim,xaxp)。 唯一的问题是,因为它是一个条形图,我的文件中不存在的数据将不会出现。例如,我希望x轴从0到64,但对于我的一些条形图,max(x轴)不是64但是小于此。
如何为所有条形图设置一个从0到64的轴,上面有几个标签?我希望那里有空值......
以下是一个例子:
Stops Month Hoursdecimal
2 May 41
3 May 16
4 May 16
5 May 40
55 June 64
65 June 39
1 July 15
2 July 14
3 August 39
5 August 15
6 August 14
7 August 40
15 August 43
3 September 40
4 September 14
5 September 14
6 September 42
74 June 40
75 June 14
76 June 13
78 June 16
4 July 28
这是我现在的脚本:
data2 <- read.csv("C:/Users/Florent/Desktop/R/Overview2014/time.csv", header = TRUE, sep=";", dec=",")
place1<-data2[data2$place=="Helsinki",]
helsinki$Hoursdecimal<-as.factor(helsinki$Hoursdecimal)
g2<- table(helsinki$Hoursdecimal)
g2<-prop.table(g2)
g2<-g2*100
barplot(g2)
barplot(g2, axe=F, space=c(0.2), las=1, col=c("gray"), ylim=c(0,35), xlim=c(0,66))
axis(2, line=-0.8, las=1, , yaxp= c(0,35,7))
axis(1, labels=F, tick=T, line=0, tck=0)
title(xlab="Hours spent at sea from previous port", line=2.2, cex.lab=1.3)
title(ylab="% of calls", line=2, las=2, cex.lab=1.3)