swirldev / swirl_courses

:mortar_board: A collection of interactive courses for the swirl R package.
http://swirlstats.com
Other
4.25k stars 7.25k forks source link

Exploratory data analysis - Lesson 2 #153

Open maribet opened 9 years ago

maribet commented 9 years ago

Near the end you compare pm25 for east and west counties in 2 scatterplots. I would have really liked to see this plots side by side with the same SCALE on the Y-AXIS for better visual comparison. Surely there is a way to do this in R?

kind regards Bettina

WilCrofter commented 9 years ago

There are indeed ways to do it in R, as covered in later lessons I believe. For now, plot can be given a ylim argument which sets the Y scale, and plots may be arranged side by side using par("mfrow") or par("mfcol"). For instance:

x <- seq(0, 2*pi, by=.1)
y1 <- cos(x)
y2 <- sin(x)
par(mfrow = c(1,2)) # 1 row of 2 plots
plot(x, y1, ylim=c(-1, 2), main="cos")
plot(x, y2, ylim=c(-1, 2), main="sin")
par(mfrow=c(1,1))

See the help files for par and ylim.

maribet commented 9 years ago

Hi William

Thank you for your answer.

Just wanted to point out, that if you compare data visually, all axes showing the same measure should also have the same scale. Otherwise, if you are not carefull, you might come to wrong conclusions. Especially while doing a “quick and dirty” exploration ;-)

Looking forward to the next lessons!

Bettina Masala Senior Specialist, Computational Statistics GfK T +49 911 395 3747

Von: William R Bauer [mailto:notifications@github.com] Gesendet: Donnerstag, 9. April 2015 03:53 An: swirldev/swirl_courses Cc: Masala, Bettina (GfK SE) Betreff: Re: [swirl_courses] Exploratory data analysis - Lesson 2 (#153)

There are indeed ways to do it in R, as covered in later lessons I believe. For now, plot can be given a ylim argument which sets the Y scale, and plots may be arranged side by side using par("mfrow") or par("mfcol"). For instance:

x <- seq(0, 2*pi, by=.1)

y1 <- cos(x)

y2 <- sin(x)

par(mfrow = c(1,2)) # 1 row of 2 plots

plot(x, y1, ylim=c(-1, 2), main="cos")

plot(x, y2, ylim=c(-1, 2), main="sin")

par(mfrow=c(1,1))

See the help files for par and ylim.

— Reply to this email directly or view it on GitHubhttps://github.com/swirldev/swirl_courses/issues/153#issuecomment-91088830.


GfK SE, Nuremberg, Germany, commercial register at the local court Amtsgericht Nuremberg HRB 25014; Management Board: Matthias Hartmann (CEO), Christian Diedrich (CFO), Dr. Gerhard Hausruckinger, Debra A. Pruent; Chairman of the Supervisory Board: Dr. Arno Mahlert This email and any attachments may contain confidential or privileged information. Please note that unauthorized copying, disclosure or distribution of the material in this email is not permitted.