boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Statistics版 - 一个R做图的问题
相关主题
再问几个R的问题。
SAS help : get macro variables as an string but not character variable.
2个初级的R问题: 包子答谢!
如何用R划两条直线?
How to compute the area between my curve and diagonal line
为什么不能把ABLINE加到散点图中了
请教:关于用R画regression line
问个简单的R问题
看似简单,但是竟然不会做。
遇到个spss graph 的问题,有人知道的话请指点
相关话题的讨论汇总
话题: temp话题: matplot话题: abline话题: state话题: data
进入Statistics版参与讨论
1 (共1页)
d*******1
发帖数: 854
1
想在一堆散点中化一条回归线.这一堆散点是五个州的数据,我想再化回归线的同时, 把
五个州的点用五种不同的颜色画出,请问怎么用R做? 谢谢
b*******g
发帖数: 513
2
matplot(data,col=1:5)
abline

【在 d*******1 的大作中提到】
: 想在一堆散点中化一条回归线.这一堆散点是五个州的数据,我想再化回归线的同时, 把
: 五个州的点用五种不同的颜色画出,请问怎么用R做? 谢谢

d*******1
发帖数: 854
3
谢了, 能说一下数据结构应该是怎么样的吗?五个州的data在五个column里? 但是我
的回归线是基于全部五个州的data...

【在 b*******g 的大作中提到】
: matplot(data,col=1:5)
: abline

b*******g
发帖数: 513
4
你用一个小data set 试过就知道。先把你的data读成一个5列的matrix在r里。用
matplot画图颜色是自动分配的。用abline添回归线时,好象先要做一个回归。这些你
用命令"?matplot" "?abline"在r里查一下就知道了。

【在 d*******1 的大作中提到】
: 谢了, 能说一下数据结构应该是怎么样的吗?五个州的data在五个column里? 但是我
: 的回归线是基于全部五个州的data...

s******d
发帖数: 2730
5
assume you have x, y, state three variables
x, y are the data with the five states pooled together
and state is the label (say, 1, 2, 3, 4, 5, etc)
You only need to use
> plot(x, y, col=state)
> abline(lsfit(x,y)$coef)

【在 d*******1 的大作中提到】
: 想在一堆散点中化一条回归线.这一堆散点是五个州的数据,我想再化回归线的同时, 把
: 五个州的点用五种不同的颜色画出,请问怎么用R做? 谢谢

d*******1
发帖数: 854
6
谢了, 楼上两位的建议很好, 总算弄出了个图, 可是我的state variable 是character
, 有什么办法让col=认character variable呢?

【在 s******d 的大作中提到】
: assume you have x, y, state three variables
: x, y are the data with the five states pooled together
: and state is the label (say, 1, 2, 3, 4, 5, etc)
: You only need to use
: > plot(x, y, col=state)
: > abline(lsfit(x,y)$coef)

s******d
发帖数: 2730
7
I know matplot works. But if you have different numbers of obs from each
state and different x levels for each state, that could be a little tricky.
Still doable.
For your question. See the following example.
temp<-sample(c(rep("NY",3), rep("NC", 2), rep("AL", 4)))
temp
temp<-as.factor(temp)
temp
temp<-as.numeric(temp)
temp

character

【在 d*******1 的大作中提到】
: 谢了, 楼上两位的建议很好, 总算弄出了个图, 可是我的state variable 是character
: , 有什么办法让col=认character variable呢?

b*******g
发帖数: 513
8
你还可以考虑用legend把你的图costomize 一下。用帮助看legend的用法.

【在 d*******1 的大作中提到】
: 想在一堆散点中化一条回归线.这一堆散点是五个州的数据,我想再化回归线的同时, 把
: 五个州的点用五种不同的颜色画出,请问怎么用R做? 谢谢

1 (共1页)
进入Statistics版参与讨论
相关主题
遇到个spss graph 的问题,有人知道的话请指点
Residuals as the new DV for a part of the sample?
M个点中选择N个点代表那M个点的问题
问一个回归问题 (转载)
[转载] Re: SAS plot problem
请教在R里面如何拆character string.
What is wrong with following code?
another sas question
[合集] sas 的一个问题
[合集] 请教Excel 操作 (Excel 2007)
相关话题的讨论汇总
话题: temp话题: matplot话题: abline话题: state话题: data