1

I know there are heaps of other posts asking the same question but I didn't understand any of the answers because I am 100% new to all of this and don't even understand ggplot yet. I need to plot two graphs onto one without using ggplot, but I'm not even sure if that's possible. This is my first graph:

 plot(AustraliaData$year4, AustraliaData$exp_mean, type = "l", col = "purple", xlab = "Year", ylab = "Australian Average", main = "Ambient Particulate Matter Pollution")

And this is my second graph:

plot(AfghanistanData$year4, AfghanistanData$exp_mean, type = "l", col = "purple", xlab = "Year", ylab = "Afghanistan Average", main = "Ambient Particulate Matter Pollution")

Firstly, do you think that using ggplot will make these graphs look nicer, and will it then be easier to graph them together? I want to make a comparison between the two countries.

If ggplot is easier, where can I find a good tutorial on how to do it? I have only been doing this stuff for a few weeks because my university course requires it as a prerequisite in STEM subjects.

Thanks!

Here is a linkto the [first bunch of data] [1]
a link to [the second bunch of data] [2]
and to [the first graph] [3]
and also [the second graph] [4]


  [1]: https://i.stack.imgur.com/K22SX.png
  [2]: https://i.stack.imgur.com/QyXxV.png
  [3]: https://i.stack.imgur.com/xUN0a.png
  [4]: https://i.stack.imgur.com/mgwkl.png
  • "do you think that using ggplot will make these graphs look nicer" Hard to say, could you post your data or at least a picture of what the graph looks like? I love `ggplot`, so if you post your data I could give you a walkthrough of how to do it that way – camille Apr 25 '18 at 12:48
  • Hi, thank you for answering! Where should I post my data? just add it to the post? I am adding it now, any help would be great, thanks!! – Emily Schroder Apr 25 '18 at 23:53
  • Yes, see [here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610) for specifics on how to post an R question that is easy for us to answer. Pasting in the output of calling `dput` on your data is the best way to go – camille Apr 26 '18 at 00:33

2 Answers2

1

A very simple way, if you prefer to use base R, is as follows:

plot(AustraliaData$year4, AustraliaData$exp_mean, xlab = "Year", ylab = "Average", main = "Ambient Particulate Matter Pollution")
lines(lowess(AustraliaData$year4, AustraliaData$exp_mean), col = "purple")
points(AfghanistanData$year4, AfghanistanData$exp_mean)
lines(lowess(AfghanistanData$year4, AfghanistanData$exp_mean), col = "green")

Note that you may need to specify xlim= and ylim= in your call to plot() to ensure that both datasets are "in frame"

Luke Hayden
  • 692
  • 4
  • 8
0

welcome to R.
As beginning I want to recommend the Book R for Data Science" by Hadley Wickham to you. It's a great place to start and includes everything you need to know about ggplot2.
To answer your question, which by the may lacks a reproducable example, try par(mfcol = c(2,1)) - it will split your plotting window into two horiontal ones; par(mfcol = c(1,2)) does the same but splits vertically. Last but not least return to "normal" by typing par(mfcol = c(1,1)).
Best wishes!

Jeremy
  • 328
  • 1
  • 8