楼主:
DrRd (就这样吧)
2015-05-30 21:30:09[问题类型]:
程式咨询(我想用R 做某件事情,但是我不知道要怎么用R 写出来)
[软件熟悉度]:
请把以下不需要的部份删除
入门(写过其他程式,只是对语法不熟悉)
[问题叙述]:
请简略描述你所要做的事情,或是这个程式的目的
我有三组在三个时间点所测量的资料,我想要把三组的资料用不同的颜色画成折线图
画在同一个图上,目前我的方法是先用plot画第一组的资料,然后再用
points把另外两组的加上去,想要问有没有其他的画法?
[程式范例]:
data <- data.frame('group' = rep(1:3,each = 3),
'time' = rep(1:3,3), 'IV' = rnorm(9, 10, 4))
with(subset(data, group == '1'),
plot(time, IV, type = 'b', col = 1, ylim = c(0,50)))
with(subset(data, group == '2'),
points(time, IV, type = 'b', col = 2, add = T))
with(subset(data, group == '3'),
points(time, IV, type = 'b', col = 3, add = T))
legend('topright', pch = 1,col = 1:3, legend = c('group1',
'group2', 'group3'))
[环境叙述]:
R3.2
[关键字]:
plot
?matplot或是library(lattice), xyplot(IV~time, groups=group)ggplot2也可以,ggplot(data, aes(x=time, y=IV, group=group)) + geom_line()