Frage

I'm fairly new to R but I am trying to create line graphs that monitor growth of bacteria over the course of time. I can successfully do this but the resulting graph isn't to my satisfaction. This is because I'm not using evenly spaced time increments although R plots these increments equally. Here is some sample data to give you and idea of what I'm talking about.

x=c(.1,.5,.6,.7,.7)
plot(x,type="o",xaxt="n",xlab="Time (hours)",ylab="Growth")
axis(1,at=1:5,lab=c(0,24,72,96,120))

As you can see there are 48 hours between 24 and 72 but this is evenly distributed on the graph, is there anyway I can adjust the scale to more accurately display my data?

War es hilfreich?

Lösung

It's always best in R to use data structures that exhibit the relationships between your data. Instead of defining growth and time as two separate vectors, use a data frame:

growth <- c(.1,.5,.6,.7,.7)
time <- c(0,24,72,96,120)

df <- data.frame(time,growth)

print(df)
   time growth
 1    0    0.1
 2   24    0.5
 3   72    0.6
 4   96    0.7
 5  120    0.7

plot(df, type="o")

Not sure if this produces the exact x-axis labels that you want, but you should be free to edit the graph now without changing the relationship between the growth and time variables.

Andere Tipps

x=data.frame(x=c(.1,.5,.6,.7,.7), y=c(0,24,72,96,120))

plot(x$y, x$x,type="o",xaxt="n",xlab="Time (hours)",ylab="Growth")
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top