0

I have been using this code to plot all the variables in my synthetic dataset, but I would like to modify it in order to compare the dataset to the main, original dataset.

   synthetic %>%
      keep(is.numeric) %>% 
      gather() %>% 
      ggplot(aes(value)) +
        facet_wrap(~ key, scales = "free") +
        geom_histogram()

I can't figure out how to make the plots go on the same, well, plots, or where to put the color values so I can tell which is which...

I tried combining both into one dataframe and using gather to inform the plots which was which but the coloring didn't work and it didn't work in general.

I tried matplot, but it told me they both have to have the same number of rows, which inclines me to believe it's not the right function for this.

The third thing I tried was:

par(mfrow=c(5,4))
i<-1
for (i in 1:26) {
  plot(synthetic[i], col = "red")
  points(full2[i], col = "blue")
}

But that failed as well. I would like all the plots to appear at once and not have to click through them.

CapnShanty
  • 529
  • 8
  • 20
  • Please take a look at [Creating a great reproducible example in R](https://stackoverflow.com/a/5963610/4421870), it's really hard to help without a sample of your data. – Mako212 Aug 07 '18 at 15:19
  • Why do I need sample data for this? It's a general question. Anybody can write something like df1<-cbind(c(1,2),c(3,4)) df2<-cbind(c(5,6),c(7,8)) and then go from there creating an example that does what I need. I am aware of the reproducible example rules already, but this is a fairly general question... – CapnShanty Aug 07 '18 at 15:44
  • Because instead of someone taking the time to create sample data that is *possibly* representative of your actual data set, you providing data removes that variable. And it means you'll get better answers because they're tailored to your actual problem. If this is a general plotting question, and not one specific to your problem, you should consult the `plot` or `ggplot` documentation. – Mako212 Aug 07 '18 at 15:55
  • Or perhaps consult [already answered questions](https://stackoverflow.com/questions/9109156/ggplot-combining-two-plots-from-different-data-frames) – Mako212 Aug 07 '18 at 15:56
  • Yes, I have a specific problem. But that specific problem does not require in any way my specific data. The two dinky little lines in my comment are sufficient to create an example that would do the job as I could then apply it to my situation on my own. – CapnShanty Aug 07 '18 at 15:59
  • That question isn't really what I'm trying to do here, I'd seen it in my searching. I need to do this for two dataframes in sum, not just overlay two plots. I don't know how to do that overlay for all the columns at once across different graphs. Hence why I asked my question. – CapnShanty Aug 07 '18 at 16:01
  • I voted them both up :) – CapnShanty Oct 24 '18 at 13:12

0 Answers0