Commit d2f9ef3a authored by Sarah Blum's avatar Sarah Blum

added graphics solutions

parent 14dc2448
# Graphics exercises
library(MASS)
data("birthwt")
# Ex 1
plot(birthwt$age, birthwt$bwt)
plot(birthwt$age, birthwt$bwt, pch = 19, col = "blue")
plot(
birthwt$age,
birthwt$bwt,
pch = 19,
col = "blue",
main = "Mother's Age Associated with \n Low Infant Birth
Weight"
)
plot(
birthwt$age,
birthwt$bwt,
pch = 15,
col = "red",
cex = 0.5,
xlab = "Mother's Age in Years",
ylab = "Birth Weight in
Grams",
main = "Mother's Age Associated with \n Low Infant Birth Weight"
)
plot(
birthwt$age,
birthwt$bwt,
pch = 15,
col = "red",
cex = 0.5,
xlab = "Mother's Age in Years",
ylab = "Birth Weight in
Grams",
main = "Mother's Age Associated with \n Low Infant Birth Weight",
type = "l"
)
# Ex 2
# install.packages("nutshell")
library(nutshell)
data(field.goals)
names(field.goals)
hist(field.goals$yards)
hist(field.goals$yards, main = "Title", col = "green")
hist(field.goals$yards,
main = "Title",
col = "green",
breaks = 35)
hist(
field.goals$yards,
main = "Title",
col = "green",
breaks = 35,
prob = TRUE
)
lines(density(field.goals$yards))
# Ex 3
library(lattice)
d <- data.frame(x = c(0:9),
y = c(1:10),
z = c(rep(c("a", "b"), times = 5)))
xyplot(y ~ x, d)
xyplot(y ~ x | z, groups = z, data = d)
xyplot(y ~ x, groups = z, data = d)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment