将直方图绘制为线条

sds*_*sds 5 plot r histogram

我想在与线条相同的图上绘制几个时间数据的直方图(1周长).

我有时间数据:

> dput(head(ts))
structure(c(1364421605.227, 1364375025.034, 1364376298.393, 1364375002.928, 
1364393158.084, 1364423268.856), class = c("POSIXct", "POSIXt"))
Run Code Online (Sandbox Code Playgroud)

我想绘制直方图.hist(ts,breaks=7*24)做工精细,但它使用的h图表类型,这将掩盖其他直方图我想补充(我知道我可以使用透明的颜色- rainbowalpha=0.5,但我真的想看到的线).

我试过了

> hist(ts, breaks = 7*24, type="l")
Warning messages:
1: In title(main = main, sub = sub, xlab = xlab, ylab = ylab, ...) :
  graphical parameter "type" is obsolete
Calls: hist -> hist.POSIXt -> myplot -> plot -> plot.histogram -> title
2: In axis(2, ...) : graphical parameter "type" is obsolete
Calls: hist -> hist.POSIXt -> myplot -> axis
3: In axis(side, at = z, labels = labels, ...) :
  graphical parameter "type" is obsolete
Calls: hist -> hist.POSIXt -> myplot -> axis.POSIXct -> axis
Run Code Online (Sandbox Code Playgroud)

为什么hist传递typetitle

我可以创建直方图对象并单独绘制它:

> h <- hist(ts, breaks=7*24, plot=FALSE)
> plot(x=h$mids, y=h$density, type="l")
Run Code Online (Sandbox Code Playgroud)

但是然后x轴标有数字(ed,"1364421605")而不是日期(例如,"Mar 25").

我想我应该使用axis,但我宁愿不自己处理 - 毕竟,hist构建我想要的轴!

谢谢!

Pie*_*nte 5

以下看起来很奇怪,因为你只给了我们六个数据点dput.您可以绘制没有x轴的线图,然后像这样添加它:

h <- hist(ts, breaks=7*24, plot=FALSE)
plot(x=h$mids, y=h$density, type="l", xaxt="n")
axis(1,at=ts,labels=format(ts,"%b-%d"))
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述