每秒显示一次刻度(旋转标签) [英] display ticks for every second observation (rotated labels)

查看:91
本文介绍了每秒显示一次刻度(旋转标签)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使我的x轴看起来正确时遇到麻烦.

我希望每秒钟出现一次刻度和标签.不幸的是,虽然我的代码显示了适当的刻度,但标签值每次都增加1.

换句话说,我希望刻度标签为2011-10-21, 2011-10-23, 2011-10-25....我的代码当前产生的刻度标签为2011-10-21, 2011-10-22, 2011-10-23 ...

我的数据框如下:

date comp_count
1 2011-10-21         10
2 2011-10-22          3
3 2011-10-23          1
4 2011-10-24          1
5 2011-10-25          1
6 2011-10-26          2

这是我正在运行的代码:

plot(my_data$comp_count, main="comped sites over time", col="blue", type='l', lwd=2,       axes=FALSE, xlab="date", ylab="count")

axis(1,at=2*0:nrow(my_data), lab=FALSE)

text(2 * 0:nrow(my_data),par("usr")[3] -1,lab = my_data $ date,srt = 45,adj = 1,xpd = TRUE,cex = 0.8)

我的图表如下: http://i.imgur.com/CjIKFCV.jpg

我想保持刻度线旋转,因为最后我将使用更多的数据.

解决方案

这是您要找的东西吗?

> with(my_data, plot(comp_count, axes = FALSE, xlab = "", type = 'l'))
> axis(2)
> axis(1, at = my_data$date, labels = FALSE)
> ticks <- my_data$date[c(TRUE, FALSE)]
> text(seq(1, length(my_data$date), 2), par("usr")[3] - 0.25, srt = 45, 
       adj = 1, labels = ticks, xpd = TRUE)
> box()

Having trouble getting my x-axis to look right.

I would like the ticks and labels to appear for every second observation. Unfortunately, while my code displays ticks appropriately, label values increase by 1 each time.

In other words I would like the tick labels to be 2011-10-21, 2011-10-23, 2011-10-25.... My code currently produces tick labels as2011-10-21, 2011-10-22, 2011-10-23 ...

My data frame looks like:

date comp_count
1 2011-10-21         10
2 2011-10-22          3
3 2011-10-23          1
4 2011-10-24          1
5 2011-10-25          1
6 2011-10-26          2

Here is the code I'm running:

plot(my_data$comp_count, main="comped sites over time", col="blue", type='l', lwd=2,       axes=FALSE, xlab="date", ylab="count")

axis(1,at=2*0:nrow(my_data), lab=FALSE)

text(2*0:nrow(my_data), par("usr")[3]-1, lab=my_data$date, srt=45, adj=1, xpd=TRUE, cex=0.8)

My chart looks like: http://i.imgur.com/CjIKFCV.jpg

I would like to keep the tick labels rotated since I will be using much more data in the end.

解决方案

Is this what you're looking for?

> with(my_data, plot(comp_count, axes = FALSE, xlab = "", type = 'l'))
> axis(2)
> axis(1, at = my_data$date, labels = FALSE)
> ticks <- my_data$date[c(TRUE, FALSE)]
> text(seq(1, length(my_data$date), 2), par("usr")[3] - 0.25, srt = 45, 
       adj = 1, labels = ticks, xpd = TRUE)
> box()

这篇关于每秒显示一次刻度(旋转标签)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆