0

I am having some very strange results with my plot in r. I wrote a Lotka-Volterra model that is working perfectly. I wanted to graph the isoclines of the parameter inputs so that they looked like this example: Isoclines of a Lotka-Volterra Model where K1/alpha>K2 and K1>K2/beta

#libraries
library(ggplot2) #uses ggplot2 for figures

#parameters
r1 = 0.5 #instantaneous growth rate for species 1
r2 = 0.5 #instantaneous growth rate for species 2
initialN1 = 5 #initial population size for species 1
initialN2 = 5 #initial population size for species 2
alpha11 = 0.009 #the effect of species 1 on species 1 (intraspecific comp)
alpha12 = 0.01 #the effect of species 1 on species 2 (interspecific comp)
alpha21 = 0.01 #the effect of species 2 on species 1 (interspecific comp)
alpha22 = 0.011 #the effect of species 2 on species 2 (intraspecific comp)
totaltime = 100 #time steps to run

#Calculate isocline Values
K1<-(1/alpha11) #carrying capacity of species 1 = 111.1111
K2<-(1/alpha22) #carrying capacity of species 2 = 90.90909
K1.alpha<-((1/alpha11)*(alpha11/alpha12)) #K1/alpha = 100
K2.beta<-((1/alpha22)*(alpha22/alpha21)) #K2/beta = 100

#bind together isocline values and give appopriate row/col names
isoclines<-data.frame(rbind(c("N1 Isocline",K1,0),c("N1  
Isocline",0,K1.alpha),c("N2 Isocline",K2.beta,0),c("Isocline N2",0,K2)))
row.names(isoclines)<-rbind("K1", "K1/alpha","K2/beta","K2")
colnames(isoclines)<-c("Isocline","N1","N2")

#plot isoclines
ggplot(isoclines, aes(x = N1, y = N2)) + geom_point()

Results from ggplot2

If you look at the graph, you can see that the the values of K1/alpha (=100) is BELOW the value of K2 (=90.909) on the y-axis. Why is this happening? Why is the lower value appearing above the higher value?

farver
  • 1
  • 1
  • When you have string or factor columns, they have an order associated with them (the order of the levels) which will default to alphabetical unless you specify otherwise. You can either reorder the levels as you see fit or convert to a numeric data type. – Gregor Thomas Sep 16 '16 at 23:09
  • [This is perhaps a more canonical dupe](http://stackoverflow.com/q/5208679/903061), although this one seems to be specifically about a bar chart, the `geom` used doesn't matter for the ordering of the axis, so it applies just as well. – Gregor Thomas Sep 16 '16 at 23:12

0 Answers0