0

I've got following data:

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

I've downloaded it from this website with help of this topic. Now I want to plot it to look similiar like data from website above. I've used:

my_x <- c(3,6,12,24,12*5,10*12,30*12)
plot(my_x,data$Coupon, type = "l")

But it doesn't look nice, because of values at x axis, but I don't know how to convert first column into desirable format. I've tried to use ggplot2, but I failed as well.
It may be helpful as well:

str(data)
'data.frame':   7 obs. of  7 variables:
 $ Tenor  : Factor w/ 7 levels "10 Year","12 Month",..: 5 7 2 3 6 1 4
 $ Coupon : Factor w/ 5 levels "0.0000","0.3750",..: 1 1 1 2 3 4 5
 $ Price  : Factor w/ 7 levels "0.0150","0.0550",..: 1 2 3 7 6 4 5
 $ Last   : Factor w/ 7 levels "0.02%","0.06%",..: 1 2 3 4 5 6 7
 $ 1 Month: Factor w/ 6 levels "+1","+10","+2",..: 1 3 3 2 6 5 4
 $ 1 Year : Factor w/ 7 levels "-1","+17","+20",..: 5 4 1 3 2 6 7
 $ Time   : Factor w/ 7 levels "06:22:02","06:35:23",..: 6 1 7 3 4 5 2
Community
  • 1
  • 1
Photon Light
  • 757
  • 14
  • 26

1 Answers1

0

str(data) showed that your data are of factor class. But they should be numeric. So you need to convert your data from factor to numeric.

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

Afterwards, plot should work.

Jot eN
  • 6,120
  • 4
  • 40
  • 59
  • I'm sorry, but it dosen't :( I mean it works, as it worked before conversion, but it LOOKS bad. I want to have on x axis something like "3m, 6m, 12m, 2Y..." etc., but I have "0, 50, 100, 200...". – Photon Light Nov 12 '14 at 13:39
  • you need to convert that numbers to dates or character – Jot eN Nov 12 '14 at 13:45
  • How? I do my_x <- as.character(data$Tenor); my_y <- as.numeric(as.character(data$Coupon)) and it still sucks. I'm not sure if I got understood. f you want to reproduce my data you need to go to one of the topic I linked and only change url, and then data <-tables[[which.max(n.rows)]]. I've made my_x just for example, because I didn't know how to get it. – Photon Light Nov 12 '14 at 13:52