Matplot不绘制数据集

时间:2016-03-14 13:25:52

标签: r plot

我试图使用matplot在R中绘制我的数据,但是,它没有绘制数据集中的数据。我的代码如下所示:

#----------------------------------------------------------------------------------------#
# RING data: Mikkel
#----------------------------------------------------------------------------------------#
# Set working directory
setwd

#### Read data & Converting factors ####
dat <- read.table("R SUM kopi.txt", header=TRUE)  
str(dat)
dat$Vial <- as.factor(dat$Vial)
dat$Line <- as.factor(dat$Line)
dat$rep <- as.factor(dat$rep)
dat$fly <- as.factor(dat$fly)  
str(dat)

mtdata <- droplevels(dat[dat$Line=="20",])
mt1data <- droplevels(mtdata[mtdata$rep=="1",])


lab<- c(expression(t[5]),expression(t[10]),expression(t[15]),expression(t[20]),
        expression(t[25]),expression(t[30]))

matplot(mt1data, type="p", bty="n", xlim=c(7,12), ylim=c(1,1150), xlab="Time", 
        ylab="mm above bottom (sum)", las=1, xaxt="n", pch=1, col="black")
axis(side=1, at=c(7:12), label=lab)

我的数据集的输出如下所示:

  

结构(列表(Vial =结构(c(6L,14L,4L,10L,13L,8L,5L,9L,   7L,12L,3L,2L,1L,11L),.标签= c(“82”,“84”,“86”,“90”,“99”,   “102”,“105”,“106”,“107”,“114”,“128”,“136”,“148”,“154”),类   =“因子”),Conc =结构(c(1L,1L,2L,2L,3L,3L,4L,4L,5L,5L,6L,6L,7L,7L),. Label = c(“a”, “b”,“c”,“d”,“e”,“x”,“y”),   class =“factor”),Line =结构(c(1L,1L,1L,1L,1L,1L,1L,1L,   1L,1L,1L,1L,1L,1L),。标签=“20”,等级=“因子”),       性别=结构(c(1L,2L,1L,2L,1L,2L,1L,2L,1L,2L,       1L,2L,1L,2L),. Label = c(“f”,“m”),class =“factor”),       rep =结构(c(1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,       1L,1L,1L,1L),。标签=“1”,类=“因子”),fly =结构(c(1L,       1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L),。标签=“1”,等级=“因子”),       t05 =结构(c(1L,3L,4L,14L,2L,12L,10L,5L,7L,       6L,8L,13L,11L,9L),. Label = c(“227,58”,“240,39”,“244,35”,       “252,56”,“274,05”,“293,01”,“307,41”,“307,96”,“349,65”,       “359,25”,“382,18”,“440,50”,“466,01”,“580,44”),class =“factor”),       t10 =结构(c(1L,4L,3L,14L,2L,12L,11L,9L,7L,       6L,5L,13L,10L,8L),. Label = c(“293,88”,“335,89”,“374,51”,       “376,65”,“380,28”,“383,73”,“405,51”,“423,63”,“425,79”,       “426,08”,“427,69”,“552,84”,“615,73”,“725,58”),class =“factor”),       t15 =结构(c(2L,7L,10L,14L,1L,12L,3L,9L,4L,       8L,11L,13L,5L,6L),. Label = c(“423,10”,“445,26”,“469,83”,       “476,26”,“488,00”,“519,04”,“526,80”,“532,71”,“547,83”,       “577,98”,“596,84”,“683,46”,“739,32”,“795,60”),class =“factor”),       t20 =结构(c(4L,8L,7L,13L,1L,12L,3L,10L,5L,       11L,6L,14L,2L,9L),. Label = c(“527,28”,“551,07”,“553,50”,       “575,46”,“581,73”,“627,94”,“635,94”,“654,21”,“661,23”,       “674,73”,“724,77”,“777,60”,“862,02”,“991,80”),class =“factor”),       t25 =结构(c(5L,10L,7L,12L,3L,13L,4L,11L,6L,       14L,8L,1L,2L,9L),. Label = c(“1077,48”,“603,97”,“633,06”,       “652,59”,“674,40”,“680,19”,“721,18”,“748,74”,“757,89”,       “760,05”,“792,99”,“845,70”,“864,54”,“876,39”),class =“factor”),       t30 =结构(c(10L,7L,6L,11L,4L,13L,3L,12L,5L,       14L,8L,1L,2L,9L),. Label = c(“1099,08”,“638,59”,“703,89”,       “744,06”,“751,95”,“772,48”,“795,15”,“800,40”,“820,53”,       “821,16”,“828,24”,“869,67”,“912,66”,“938,97”),class =“factor”)),. Name = c(“Vial”,“Conc” “,”Line“,”Sex“,”rep“,”fly“,   “t05”,“t10”,“t15”,“t20”,“t25”,“t30”),row.names = c(1L,5L,8L,   12L,13L,18L,21L,23L,25L,28L,32L,35L,38L,42L),等级=   “data.frame”)

我得到的结果是:由于我的数据集中的最高值高于1000,似乎正在绘制某些东西,我只是不知道它是什么。 enter image description here

1 个答案:

答案 0 :(得分:1)

这很可能是一个数据读取问题;阅读dput结果并在结果上运行str()即表示

 $ t05 : Factor w/ 14 levels "227,58","240,39",..: 1 3 4 14 2 12 10 5 7 6 ...

这意味着您的变量已作为因子而不是数字读入。请参阅How to read in numbers with a comma as decimal separator?,特别是尝试

dat <- read.table("R SUM kopi.txt", header=TRUE, dec=",")