0

Can you help with solution? I'm trying to plot my DF, I have an input:

DF <- data.frame(
    country=c("AG","AT","BE","FB"),
    W1990=c(2233,3213,1221,2432),
    W1991=c(2443,2273,2290,2303),
    W1992=c(3544,3423,2223,2989),
    I1990=c(22,32,23,32),
    I1991=c(25,37,24,33),I1992=c(30,40,29,40)
)

my x axies - W1990, W1991, W1992, W1993, W1994, and y axies - I1990, I1991, I1992, I1993, I1994

With simple plot function, I can do something like that:

plot(DF$W1990, DF$I1990) 
points(DF$W1991, DF$I1990)

.... and so on, i have 36 columns, so it's pretty annoying....

But, is there any way to make it more elegant using ggplot, and put corresponding name of country vector on the plot?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Dima Sukhorukov
  • 129
  • 4
  • 13
  • Check out the question marked as duplicate. The trick is to reshape (or `melt()`) your data. – MrFlick Feb 11 '15 at 03:27
  • Actually, i see your example is a bit more complicated. If you use some helper libraries: `library(tidyr); library(magrittr); library(ggplot2)` you can do `DF %>% gather(code,val, -country) %>% separate(code, c("WI","Year"), 1) %>% spread(WI, val) %>% ggplot(aes(x=W, y=I, col=Year, pch=country)) + geom_point()`. The idea is the same. Reshape your data. – MrFlick Feb 11 '15 at 03:39

0 Answers0