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 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 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 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 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 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 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 : }
|
|