【发布时间】:2016-01-08 00:47:49
【问题描述】:
我在一段时间内有一些风速和风向数据,我需要将其绘制成羽状图。
在网上冲浪了一段时间后,我发现有人写了一个函数来绘制对我有用的羽毛图(谢谢你正在阅读这篇文章!!)。我现在的问题是我不知道如何操作 x 轴的标签。
绘制完成后,图如下: 现在 x 轴在这里看起来并不算太糟糕,但想象一下我有 200 个数据点(因此刻度)而不是 10 个,并且轴刻度可能会有点混乱。所以我希望有人可以帮助我操纵 x 轴,特别是弄乱滴答声。
绘制图形的代码是:
stg <- scan(what="", sep="\n")
9/20/15_12:00 2.597058824 157.9411765
9/21/15_0:00 2.177192982 185.1754386
9/21/15_12:00 2.577391304 189.2173913
9/22/15_0:00 1.984955752 237.4336283
9/22/15_12:00 3.993859649 252.6315789
9/23/15_0:00 1.613392857 175.5357143
9/23/15_12:00 3.849166667 216.8333333
9/24/15_0:00 2.138135593 117.0338983
9/24/15_12:00 3.32605042 216.302521
9/25/15_0:00 1.490178571 239.8214286
df <- read.table(textConnection(stg), sep="")
colnames(df) <- c("Time", "wsp", "wdir")
df$PTime <- as.POSIXct(df$Time, format="%m/%d/%y_%H:%M")
feather.plot2 <- function (r, theta, xpos, yref = 0, use.arrows = TRUE, col.refline = "lightgray",
fp.type = "s", main = "", xlab = "", ylab = "", xlabels = NULL,
...)
{
if (missing(xpos))
xpos <- 1:length(theta)
if (fp.type == "m")
theta <- 5 * pi/2 - theta
x <- r * cos(theta)
y <- r * sin(theta)
xmult <- diff(range(xpos))/(diff(range(y)) * 2)
x <- x * xmult
xlim <- range(c(xpos, x + xpos))
ylim <- range(c(y, yref))
oldpin <- par("pin")
xdiff <- xlim[2] - xlim[1]
ydiff <- ylim[2] - ylim[1]
plot(0, xlim = xlim, ylim = ylim, type = "n", main = main,
xlab = xlab, ylab = ylab, axes = TRUE, xaxt = "n")
box()
if (is.null(xlabels))
axis(1)
else axis(1, at = xpos, labels = xlabels)
abline(h = yref, col = col.refline)
if (use.arrows)
arrows(xpos, yref, xpos + x, y, length = 0.1, ...)
else segments(xpos, yref, xpos + x, y, ...)
par(pin = oldpin)
}
feather.plot2(df$wsp, df$wdir, fp.type="m", xlabels=df$PTime)
而我想要的是在 12:00 有较大的刻度,在 0:00 有较小的刻度,如下图所示:
虽然我不知道为什么这个数字的标签是“Sun - Thu”而不是日期......
这个图的代码是:
daterange=c(min(df$PTime), max(df$PTime))
plot(x=df$PTime, y=df$wsp, xaxt="n", type="l")
axis.POSIXct(1, at=seq(daterange[1], daterange[2], by="day"))
axis.POSIXct(1, at=seq(daterange[1], daterange[2], by="12 hours"), tcl = -0.3, labels=FALSE )
我尝试在羽化图上使用这些轴命令,但它不起作用。所以我很感激任何帮助/建议。非常感谢!!
【问题讨论】: