-
Notifications
You must be signed in to change notification settings - Fork 3
Plot
Gota Morota edited this page Mar 5, 2017
·
3 revisions
Say we wish to maximize (a+b)^4b^5exp(-(a+2*b)).
model = function(a,b){
(a+b)^4*b^5*exp(-(a+2*b))
}
X = seq(-2, 10,0.1)
Y = seq(1, 10,0.1)
Z = outer(X,Y ,model)
contour(X,Y,Z, xlab="mu", ylab="lambda")pdf(file="hoge.pdf", onefile=TRUE)
plot(y1~x1)
plot(y1~x1)
plot(y1~x1)
dev.off()x <- read.table(textConnection("Group Ind Age Trait
1 1 2 21
1 2 1 22
1 2 2 21
1 3 1 24
1 3 2 45
1 4 1 23
1 4 2 26
2 1 1 45
2 1 2 12
2 2 1 25
2 2 2 26
2 3 1 45
2 3 2 43
2 4 1 23
2 4 2 47
"), header=T)
closeAllConnections()
# base graphics
par(mfrow = c(1,2))
plot(Trait ~ Age, data = x, subset = {Group == 1})
plot(Trait ~ Age, data = x, subset = {Group == 2})
# lattice
require(lattice)
xyplot(Trait ~ Age | Group, data = x)
# ggplot2
require(ggplot2)
g <- ggplot(x, aes(x = Age, y = Trait))
g + geom_point(size = 2.5) + facet_wrap(~ Group) + theme_bw()Beta distribution with a = 1, b = 0.67.
curve(dbeta(x,1,0.67), 0, 1, yaxt="n", xlab="theta", ylab="")# lattice
require(lattice)
xyplot(Reaction~Days, data=sleepstudy, group=Subject, type='l',
panel= function(...) {
panel.xyplot(...)
panel.average(...,fun=mean, horizontal=FALSE, col='red', lwd=3)
}
)
# ggplot2
require(ggplot2)
g <- ggplot(sleepstudy, aes(x = Days, y = Reaction, group = Subject, colour + = Subject))
g + geom_line(size = 1) + geom_smooth(aes(group = 1), size = 2) + theme_bw()
# get rid of the legend
g + geom_line(size = 1) +geom_smooth(aes(group = 1), size = 2) + theme_bw() +opts(legend.position = 'none')data(mtcars)
with(mtcars, plot(mpg,disp))
dev.new()
with(mtcars, plot(mpg,wt))x <- seq(-4, 4, 0.1)
y <- dnorm(x)
plot(x, dnorm(x), type="l", col="black", lwd=3)
abline(v=-1, lwd=3, col="blue")
abline(h=0, lwd=3, col="black")
polygon(c(x[1:31],rev(x[1:31])), c(rep(0,31),rev(y[1:31])), col="lightblue")