Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 使用不同的x轴打印_R_Plot_Ggplot2 - Fatal编程技术网

R 使用不同的x轴打印

R 使用不同的x轴打印,r,plot,ggplot2,R,Plot,Ggplot2,我得到了以下数据: data Tenor Coupon Price Last 1 Month 1 Year Time 1 3 Month 0.0000 0.0150 0.02% +1 -4 06:45:02 2 6 Month 0.0000 0.0550 0.06% +2 -3 06:22:02 3 12 Month 0.0000 0.0950 0.10% +2 -1 06:50:35 4 2 Year 0.

我得到了以下数据:

data  
 Tenor Coupon   Price  Last 1 Month 1 Year     Time
1  3 Month 0.0000  0.0150 0.02%      +1     -4 06:45:02
2  6 Month 0.0000  0.0550 0.06%      +2     -3 06:22:02
3 12 Month 0.0000  0.0950 0.10%      +2     -1 06:50:35
4   2 Year 0.3750  99-22¾ 0.52%     +10    +20 06:37:41
5   5 Year 1.5000  99-14½ 1.62%      +9    +17 06:37:58
6  10 Year 2.3750  100-12 2.33%      +6    -44 06:40:21
7  30 Year 3.1250 101-10½ 3.06%      +5    -80 06:35:23
我已经从这个网站上下载了它。 现在我想把它画成类似于上面网站的数据。我用过:

my_x <- c(3,6,12,24,12*5,10*12,30*12)
plot(my_x,data$Coupon, type = "l")
str(数据)表明您的数据属于因子类。但它们应该是数字。因此,您需要将数据从因子转换为数值

data$Coupon <- as.numeric(as.character(data$Coupon))

data$优惠券很抱歉,但它没有:(我的意思是它可以工作,因为它在转换之前工作,但它看起来很糟糕。我想在x轴上有一些像“3m,6m,12m,2Y…”之类的东西,但我有“0,50100200…”。你需要将这些数字转换为日期或字符如何?我做我的x为什么你不使用plot(我的x,数据$Tenor,type=“l”)?因为它绘制了错误的图形?你试过了吗?我试过了,但它看起来不像我链接的网站上的图形。
data$Coupon <- as.numeric(as.character(data$Coupon))