我有一个数据帧称为fin
:用R绘制一个数据框的子集?
str(fin)
'data.frame': 158 obs. of 9 variables:
$ Species : chr "TRAT" "TRAT" "TRAT" "WRAT" ...
$ Site : chr "BAN" "BEX" "BEX" "BEX" ...
$ Year : chr "2011" "2010" "2011" "2012" ...
$ FR.CoYear: num 35.7 123.6 136.4 215.8 145.2 ...
$ Sample : int 31 NA 929 809 NA NA NA 30 215 NA ...
$ Young : num 16 NA 828 709 NA NA NA 45 235 NA ...
$ SiteYear : Factor w/ 65 levels "BAN 2011","BAN 2012",..: 1 4 5 6 7 1
我想绘制FR.CoYear
针对(fin$Young/fin$Sample)
单独为每个所述5种在$Species
。
我试过了建议的方式here;但目前没有任何工作,我会非常感谢指导 - 这只是一个语法问题?
这是我曾尝试:
with(subset(fin,fin$Species == "TRAT"), plot(fin$FR.CoYear, fin$Young /fin$Sample))
## runs without error but no plot is produced
with(fin[fin$Species == "TRAT",], plot((fin$FR.CoYear, fin$Young/fin$Sample))
##gives the error: unexpected ',' in "with(fin[fin$Species == "TRAT",], plot((fin$FR.CoYear,"
plot(fin$FR.CoYear[fin$Species == "BLKI"],fin$Young/fin$Sample[fin$Species == "BLKI"])
##Error in xy.coords(x, y, xlabel, ylabel, log) :
'x' and 'y' lengths differ
我道歉,如果这是很基本的,但我自学R.
以供将来参考,这将是更容易帮助你,如果你提供一个[重复的例子(http://stackoverflow.com/questions/5963269/how-to-make-a-大-R重现-例子)。在这种情况下,这意味着您的数据样本(除了您已经提供的代码和解释)。 – eipi10 2014-09-26 17:00:54