0
votes

Im trying to plot my data in R using matplot, however, it's not plotting the data from the dataset. My code looks like this:

#----------------------------------------------------------------------------------------#
# 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)

Dput of my dataset looks like this:

structure(list(Vial = structure(c(6L, 14L, 4L, 10L, 13L, 8L, 5L, 9L, 7L, 12L, 3L, 2L, 1L, 11L), .Label = c("82", "84", "86", "90", "99", "102", "105", "106", "107", "114", "128", "136", "148", "154"), class = "factor"), Conc = structure(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 = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "20", class = "factor"), Sex = structure(c(1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L), .Label = c("f", "m"), class = "factor"), rep = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "1", class = "factor"), fly = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "1", class = "factor"), t05 = structure(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 = structure(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 = structure(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 = structure(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 = structure(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 = structure(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")), .Names = 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), class = "data.frame")

And the result i get is this: As the highest values in my dataset is above a 1000 it seems that something is being plotted, i just dont know what it is. enter image description here

1

1 Answers

1
votes

This is most likely a data-reading problem; reading in your dput results and running str() on the results shows e.g.

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

which means that your variables have been read in as factors rather than as numerics. See How to read in numbers with a comma as decimal separator? and in particular try

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