我有一个名为fin的数据框架
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)分别画成$Species中的5个物种。
我尝试了建议的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。
发布于 2016-09-03 18:06:06
你可以试试这个:
基本地块,即两个物种的地块:
plot(FR.CoYear ~ Young/Sample, data=subset(fin, Species == "TRAT"))
points(FR.CoYear ~ Young/Sample, col="red",data=subset(fin, Species == "WRAT"))要增加更多的物种,只需添加更多的点数()。
ggplot2,即两种:
ggplot(subset(fin, Species %in% c("TRAT", "WRAT")),
       aes(x=FR.CoYear,
       y=Young/Sample,
       color=Species))+
  geom_point()要在这里添加更多的物种,只需添加列表c()中的引用即可。
我认为这对您有用,如果需要,只需测试和更正var名称即可。
我最诚挚的问候
https://stackoverflow.com/questions/26064031
复制相似问题