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?

2
  • Check out the question marked as duplicate. The trick is to reshape (or melt()) your data. Commented Feb 11, 2015 at 3: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. Commented Feb 11, 2015 at 3:39

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.