由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Statistics版 - How to selectively plot data in R
相关主题
[合集] 电话面试完了,肯定没戏,大家帮我看看题目,就算学习吧[R] R plot histogram question about breaks
correlation clustering用spss, stata, 或 r怎么做Is STATA better than SAS and R in plotting?
bond price data clearn (转载)How to make image.plot in sas
问一个R的问题output multiple files in a do loop
请教一个用R画图的问题请问怎么做个plot,各数据点可以标注不同颜色
请问诸位高手:lattice比一般的画图plot之类[转载] Re: SAS plot problem
R kmeans issue, plot result一个sas问题
what's wrong with Proc Reg???R plot: 用pdf(append=T) 将多个图输出到一个PDF文件
相关话题的讨论汇总
话题: state话题: data话题: plot话题: subset
进入Statistics版参与讨论
1 (共1页)
S******y
发帖数: 1123
1
I have a R data frame.
I would like to selectively plot certain rows of data (e.g. State =
'CA')
But I would not like to use subset. The reason is that I have to do it
many times on different values of select variable (e.g., State= 'CA',
and also State = 'AZ', and also State = 'FL' respectively, etc. )
Is there a way to do this via avoiding subset (i.e., physically creating
the subset of data satisfying the select condition)?
Many thanks!
l*****k
发帖数: 587
2
I guess you can write an easy function that takes arguement
like CA, AC or FL, subset it in function then do the plot
you can make your funciton accepts multiple arguments so you can
do more complex subset and plotting.
you can also let your program iterate through all the varialbes,
plot to pdf or jpg file, so it runs automatically.

【在 S******y 的大作中提到】
: I have a R data frame.
: I would like to selectively plot certain rows of data (e.g. State =
: 'CA')
: But I would not like to use subset. The reason is that I have to do it
: many times on different values of select variable (e.g., State= 'CA',
: and also State = 'AZ', and also State = 'FL' respectively, etc. )
: Is there a way to do this via avoiding subset (i.e., physically creating
: the subset of data satisfying the select condition)?
: Many thanks!

S******y
发帖数: 1123
3
Thanks! I really appreciate it.
o****o
发帖数: 8077
4
I usually do it like this:
St<-names(table(data$State))
..... #set graphics environment parameters
plot(data$y[data$State==St[1]]~data$x[data$State==St[1]],....)
for (i in 2:length(St)){
lines(data$y[data$State==St[i]]~data$x[data$State==St[i]],....)
}
S******y
发帖数: 1123
5
Thanks oloolo.
That is an elegant approach too!
s*****n
发帖数: 2174
6
haha, I often do similar things, too.
But I tend to do
plot(..., type = "n")## set up graph frame, no actual lines.
for (i in 1:length(...)){
## draw each line
}

【在 o****o 的大作中提到】
: I usually do it like this:
: St<-names(table(data$State))
: ..... #set graphics environment parameters
: plot(data$y[data$State==St[1]]~data$x[data$State==St[1]],....)
: for (i in 2:length(St)){
: lines(data$y[data$State==St[i]]~data$x[data$State==St[i]],....)
: }

o****o
发帖数: 8077
7
I sometimes found I can't align my lines properly with the frame when I
tried to use your approach.
but anyway, drawing in R is fun, hehe

【在 s*****n 的大作中提到】
: haha, I often do similar things, too.
: But I tend to do
: plot(..., type = "n")## set up graph frame, no actual lines.
: for (i in 1:length(...)){
: ## draw each line
: }

1 (共1页)
进入Statistics版参与讨论
相关主题
R plot: 用pdf(append=T) 将多个图输出到一个PDF文件请教一个用R画图的问题
split-plot菜问题请问诸位高手:lattice比一般的画图plot之类
请问R中有没有MATLAB里面类似hold on的语句R kmeans issue, plot result
请教一个R作图的命令what's wrong with Proc Reg???
[合集] 电话面试完了,肯定没戏,大家帮我看看题目,就算学习吧[R] R plot histogram question about breaks
correlation clustering用spss, stata, 或 r怎么做Is STATA better than SAS and R in plotting?
bond price data clearn (转载)How to make image.plot in sas
问一个R的问题output multiple files in a do loop
相关话题的讨论汇总
话题: state话题: data话题: plot话题: subset