R 中的绘图问题 [英] Issue with Plots in R
本文介绍了R 中的绘图问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
数据:我有一个包含 2 列的数据框
Data: I have a dataframe with 2 columns
Col1 20160628 20160629 20160630 20160701 20160702
Col2 500 600 700 800 900
我需要 x 轴上的 Col1 和 y 轴上的 Col2
I need Col1 in x axis and Col2 to be y axis
当我使用 plot 制作图表时,在 x 轴上显示了 20160680 等数据点,这在图表上非常具有误导性.
When I am using plot to make the graph, on the x axis its showing the data points like 20160680 and so on, which is very misleading on the graph.
我只是需要图上等距的 5 个点.
I juts need this 5 points on the graph equally spaced.
推荐答案
你可以尝试的一个明显的事情是:
An obvious thing you can try is:
x <- c(20160628,20160629,20160630,20160701,20160702)
y <- 5:9 * 100
x <- as.character(as.Date(as.character(x),format = "%Y%m%d")) ## convert to date
# [1] "2016-06-28" "2016-06-29" "2016-06-30" "2016-07-01" "2016-07-02"
plot(y, xaxt = "n", xlab = "Date") ## do not draw x-axis
axis(1, at = 1:length(y), labels = x) ## add x-axis, using date as axis labels
这篇关于R 中的绘图问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文