1

Hey there I got a quick question,

I have the following extract of my dataset:

head(meanchangeafterdowngrade)
    `Days after downgrade` `CDS-bond basis` `Basis change                                                 
                    <dbl>            <dbl>         <dbl>
1                    -30        -27.41164     0.02152773
2                    -29        -27.13952     0.01377565
3                    -28        -27.12704     0.02781917
4                    -27        -27.10034     0.02570149
5                    -26        -27.10408     0.02681551
6                    -25        -27.10054     0.02795637

Now I would like to plot the "Days after downgrade" on the x-axis and the other 2 variables on the y-axis using ggplot. I achieved to plot them in two separate graphs, however I would like to have them in the same. I guess I should use the melt() function, but I did not quite get it yet.

rbonac
  • 125
  • 2
  • 14

1 Answers1

3

Here is an example with the iris dataset:

library(ggplot2)

dat <- reshape2::melt(iris, id.vars="Species", 
                      measure.vars=c("Sepal.Length", "Sepal.Width"))

ggplot(dat, aes(x=Species, y=value, color=variable)) + 
  geom_point()

enter image description here

Stéphane Laurent
  • 75,186
  • 15
  • 119
  • 225