简体   繁体   中英

How to plot only a specific range of data in R

I have a simple syntax question for an absolute beginner. I have been searching and experimenting and I can't figure it out. I need to only plot values from the variable SIZE that are greater than 0.8, but less than seven. I am using the with() expression along with plot(). Can someone tell me how I should write this?

with(dat[SIZE <7 | SIZE > 0.8  ,], plot(SP.RICH~SIZE))

Thank You.

Selecting only certain rows is called filtering .

One way is to use dplyr, it's a nicer idiom:

require(dplyr)
dat %>% filter(SIZE>0.8 & SIZE<7) %>%
plot(SP.RICH~SIZE, data = .)

Another is data.table package.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM