-2

I have a simple tasks I would like to do. Using an RODBC connection I have connected R to a SQL server database. There are four tables in the database and they are tenors of Libor rates

Libor_1_mos
Libor_3_mos
Libor_6_mos
Libor_12_mos

Each table has two columns. The first column shows dates and the second column shows rates.

I would like a simple chart that plots the rates based on the dates in column 1. Straightforward - that is all that needs to be done. The x-axis should be dates (column 1) and the y axis should be rates (column 2). Note it is 5 years worth of data so showing every possible date on the x-axis may not be feasible.

Here is my work so far I am using the Libor_3_mos as an example

threemosdata <- sqlQuery(con,"select * from Libor_3_mos)

Using that line I can read the data from the table. So for instance

colnames(threemosdata)

will give me the names of the column in the table.

user3195446
  • 147
  • 1
  • 13
  • And... where are you stuck? Are you aware of the `plot` function? Have you tried to use it? Do you know how data frame columns are indexed, i.e., that you can access the first column with `threemosdata[, 1]` or `threemosdata[, "name of first column"]` or `threemosdata[, variable_assigned_to_name_of_first_column]`? Do you need help converting to dates? Really it just seems like you need some introductory material. There are many excellent resources linked [in the R tag wiki](http://stackoverflow.com/tags/r/info). Please come back when you have a more specific question. – Gregor Thomas Sep 20 '16 at 16:33
  • I didn't downvote you, but I think the first challenge you have to overcome is how to first gather the data you want to plot in the form of a SQL query. You have multiple tables, and also you may need to do some aggregation to pare down the large number of records. – Tim Biegeleisen Sep 20 '16 at 16:34
  • @Gregor I'm a SQL-minded person, so I think he first actually needs to nail down his SQL query before even contemplating doing an R plot. – Tim Biegeleisen Sep 20 '16 at 16:34
  • @TimBiegeleisen with as little detail as provided I'm not convinced that aggregation is necessary - every single date might not need a label on the x-axis, but that's just a labeling issue. Or maybe not - who can say? – Gregor Thomas Sep 20 '16 at 16:38
  • @gregor I am not aware of the plot function I have never used R I am trying to learn and that is why I came here. Tim no aggregation is necessary. Only need to plot one table not all of them at once. Just one table of data- that is it. – user3195446 Sep 20 '16 at 16:38
  • @user3195446 That's what I thought. Please read some introductory material before asking questions. This is a site to help you on things that you have tried to figure out and are stuck on, not to hold your hand and create a custom tutorial. – Gregor Thomas Sep 20 '16 at 16:39
  • Get off you high horse. Implicitly I am asking questions on this forum while reading beginning material. This forum is to assist help in my learning and answer questions. In particular to help me learn faster and avoid the pitfalls of trial and error that one encounters in self learning. You have not contributed one valid comment to this posts - none. – user3195446 Sep 20 '16 at 16:47
  • 1
    Whether you believe it is fair or not, questions in the vein of "my data looks like this, I need a plot that has these characteristics, what do I do?" are unlikely to receive a positive response from this community. Generally, the presumption here is that you've made an attempt at creating the plot, can share the code and describe where specifically you're stuck. If you can't do those things, the feeling will typically be that you're not ready to ask here yet. – joran Sep 20 '16 at 17:43
  • See my answer below. @Joran you are more than welcome to accept it. – user3195446 Sep 21 '16 at 11:31

1 Answers1

1

So this worked lovely

> date <- (threemosdata$observation_date)
> rates <- (threemosdata$USD3MTD156N)
> plot(date,rates)
user3195446
  • 147
  • 1
  • 13