【发布时间】:2011-09-19 16:21:42
【问题描述】:
更新:
我已经解决了我的问题。我在找
coord_cartesian(xlim = c(800, 2100), ylim = c(0, 0.0021))
感谢每一位试图提供帮助的人!
问题是:
我想画一幅很好的图画,说明正态分布和逻辑分布之间的区别。我已经达到了这一点:
x=seq(1000,2000,length=200)
dat <- data.frame(
norm = dnorm(x,mean=1500,sd=200),
logistic = dlogis(x,location=1500,scale=200), x = x
)
ggplot(data=dat, aes(x=x)) +
geom_polygon(aes(y=norm), fill="red", alpha=0.6) +
geom_polygon(aes(y=logistic), fill="blue", alpha=0.6) +
xlab("") + ylab("") +
opts(title="Logistic and Normal Distributions") +
scale_x_continuous(expand = c(0, 0)) +
scale_y_continuous(expand = c(0, 0))
但是,后勤部分在底部被“切断”。我认为我应该做的是例如从 0 到 3000 绘制这个分布,但只显示 1000-2000。
任何线索如何做到这一点?
我试过 scale_x_continuous(limits = c(1000, 2000)) 但这不起作用
更新:
我已经更新了我的代码,所以我有了图例,现在它看起来像这样:
x=seq(700,2300,length=200)
dat2 <- data.frame(x=x)
dat2$value <- dnorm(x,mean=1500,sd=200)
dat2$type <- "Normal"
dat1 <- data.frame(x=x)
dat1$value <- dlogis(x,location=1500,scale=200)
dat1$type <- "Logistic"
dat <- rbind(dat1, dat2)
ggplot(data=dat, aes(x=x, y=value, colour=type, fill=type)) + geom_polygon(alpha=0.6) + scale_y_continuous(expand = c(0, 0))
【问题讨论】: