Nancy Reid
Feb 27
qplot
; a quick way to convert from plot
Code available as mastery.r
at http://ggplot2.org/book
library(ggplot2)
data(mpg)
head(mpg) # we'll use the fuel economony data set
manufacturer model displ year cyl trans drv cty hwy fl class
1 audi a4 1.8 1999 4 auto(l5) f 18 29 p compact
2 audi a4 1.8 1999 4 manual(m5) f 21 29 p compact
3 audi a4 2.0 2008 4 manual(m6) f 20 31 p compact
4 audi a4 2.0 2008 4 auto(av) f 21 30 p compact
5 audi a4 2.8 1999 6 auto(l5) f 16 26 p compact
6 audi a4 2.8 1999 6 manual(m5) f 18 26 p compact
Help needed!
qplot(displ, hwy, data = mpg, colour = factor(cyl))
da
qplot(displ, hwy, data=mpg, colour=factor(cyl), geom="line") +
theme(legend.position = "none")
qplot(displ, hwy, data=mpg, colour=factor(cyl), geom=" bar",
stat="identity", position = "identity") +
theme(legend.position = "none")
qplot(displ, hwy, data=mpg, colour=factor(cyl)) +
geom_smooth(data= subset(mpg, cyl != 5), method="lm")
qplot(displ, hwy, data=mpg, facets = . ~ year) + geom_smooth()
x <- 1:10
y <- factor(letters[1:5])
qplot(x, x, size = x)
qplot(x, x, 1:10, colour = x)
qplot(y, y, 1:10, shape = y)
qplot(y, y, 1:10, colour = y)
last_plot() + theme(legend.position = "right")
First make a smaller data set:
mpg2 <- subset(mpg, cyl != 5 & drv %in% c("4","f"))
Eliminates 5-cylinder cars and rear-wheel drive cars (29 in all)
qplot(cty, hwy, data = mpg2)
+ facet_grid(. ~ .)
qplot(cty, hwy, data = mpg2) + facet_grid(. ~ cyl)
qplot(cty, hwy, data = mpg2) + facet_grid(drv ~ cyl)
myplot <- qplot(Ash.dosage, Biomass..g., data = treesAS2, facets = Seedling.species ~ ., color = Seedling.species)
myplot + geom_smooth(method = "lm", formula = y ~ x + I(x^2), se = T)