简体   繁体   English

如何在R中仅绘制特定范围的数据

[英]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. 我只需要从变量SIZE中绘制大于0.8但小于7的值。 I am using the with() expression along with plot(). 我正在使用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: 一种方法是使用dplyr,这是一个更好的习惯用法:

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

Another is data.table package. 另一个是data.table包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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