0

I have four dataframes (say A,B,C and D). The data in each dataframe is of the format given below. But each dataframe is of a different length.

 lon       lat           area              fd              tp       rt
-85.40944   41.88833    274.5387    1.100000e+02    50.00000000 60.0000000
-85.40944   41.88833    274.5387    1.140000e+02    31.00000000 83.0000000
-85.40944   41.88833    274.5387    6.040000e+02    76.00000000 528.0000000
-85.40944   41.88833    274.5387    1.000000e+00    1.00000000  0.0000000
-85.40944   41.88833    274.5387    3.340000e+02    32.00000000 302.0000000

I want to extract (for example) FD columns and the LON columns from four dataframes. And after that plot something like this, but instead of one blob, it will be four blobs of Lon v/s FD figures. enter image description here

Questions:

  1. Because of uneven lengths, I am unable to use MELT. How do I do it so that it is easier to plot in ggplot2?
Geekuna Matata
  • 1,349
  • 5
  • 19
  • 38
  • Why is my question being downvoted? I put so much effort to give detailed explanation of my problem. :( – Geekuna Matata Mar 25 '14 at 18:43
  • I don't understand what `melt` has to do with this. Add a group variable to each data.frame and then `rbind` them. – Roland Mar 25 '14 at 18:46
  • Hi Roland, thank you. I have used melt to format data for ggplot before. But never used rbind. Would you mind giving some example code for this? I am in a learning phase. Apologies for being a newbie. – Geekuna Matata Mar 25 '14 at 18:47
  • `rbind(cbind("DF1", DF1), cbind("DF2", DF2), ...)` assuming your data frames are `DF1`, `DF2`, etc. This will create a single data frame with an extra column indicating the source data frame. You can then use `facet_wrap` from `ggplot` using the column indicating what original data frame your data came from. – BrodieG Mar 25 '14 at 18:53
  • Do something like `A$g <- "A"; B$g <- "B"; C$g <- "C"; D$g <- "D"; DF <- do.call(rbind, list(A, B, C, D))`. If they don'z have the same columns, subset them first. – Roland Mar 25 '14 at 18:53
  • @BrodieG Thanks. I tried, but got this error: **Error in match.names(clabs, names(xi)) : names do not match previous names** However, all names are same. I checked with the identical function and got invalid **'num.eq' value** – Geekuna Matata Mar 25 '14 at 19:04
  • Try: `rbind(cbind(id="DF1", DF1), cbind(id="DF2", DF2), ...)` (note the added `id=`). – BrodieG Mar 25 '14 at 19:19

1 Answers1

1
reshape2::melt(list(A=A, B=B, C=C, D=D), id="fd", meas="lon")
baptiste
  • 75,767
  • 19
  • 198
  • 294