- 阅读权限
- 255
- 威望
- 0 级
- 论坛币
- 706 个
- 通用积分
- 5.7057
- 学术水平
- 3 点
- 热心指数
- 8 点
- 信用等级
- 3 点
- 经验
- 8237 点
- 帖子
- 36
- 精华
- 0
- 在线时间
- 134 小时
- 注册时间
- 2015-7-7
- 最后登录
- 2020-8-23
本科生
还不是VIP/贵宾
- 威望
- 0 级
- 论坛币
- 706 个
- 通用积分
- 5.7057
- 学术水平
- 3 点
- 热心指数
- 8 点
- 信用等级
- 3 点
- 经验
- 8237 点
- 帖子
- 36
- 精华
- 0
- 在线时间
- 134 小时
- 注册时间
- 2015-7-7
- 最后登录
- 2020-8-23
| 开心 2019-3-6 21:04:01 |
---|
签到天数: 219 天 连续签到: 1 天 [LV.7]常住居民III
|
20论坛币
- library(ggplot2)
- x=seq(0,10,length=300)
- df <- data.frame(x = x,y = x/2,
- z1 = x/2+sqrt(x),
- z2 = x/2-sqrt(x)) #c("x","mean","mean+SD","mean-SD")
- ggplot(df, aes(x,y,colour = "mean")) +
- geom_line(lwd = 1.5) +
- geom_line(aes(x=x,y=z1,colour="mean+SD"), lty = 2, lwd = 1.6) +
- geom_line(aes(x=x,y=z2,colour="mean-SD"), lty = 2, lwd = 1.6) +
- scale_y_continuous(limits = c(-1,9)) +
- scale_x_continuous(limits = c(0,11)) +
- theme(legend.title=NULL) +
- theme(legend.position=c(.1,0.9)) +
- theme(legend.background=element_blank()) +
- theme(legend.key=element_blank()) +
- labs(x="time")
复制代码
- plot(x,x/2,type="l",ylim=c(-1,9), xlim=c(0,11),
- lwd=2,ylab="",xlab="time")
- lines(x,x/2+sqrt(x),lty=2,lwd=2)
- lines(x,x/2-sqrt(x),lty=2,lwd=2)
- legend("topleft",c("mean","mean+SD","mean-SD"),
- lwd=2,lty=c(1,2,2))
复制代码
|
最佳答案
zerofung 查看完整内容
theme(legend.title=NULL)改为theme(legend.title=element_blank())
最后加一层scale_color_manual(values = c("red","blue","black"))
|