Reputation: 1243
I have the following Markov chain:
pre<-cbind(c(rep("rain",100),rep("sun",100),rep("rain",100)))
post<-cbind(c(rep("rain",50),rep("sun",70),rep("rain",100),rep("sun",80)))
df<-cbind(pre,post)
df<-as.data.frame(df)
colnames(df)<-c("pre","post")
states<-c("rain","sun")
probsCase<-function(i,j){
sum(as.character(df$pre)==states[i] & as.character(df$post)==states[j])/sum(as.character(df$pre)==states[i])
}
transitionMatrix<-outer(1:2,1:2,Vectorize(probsCase))
colnames(transitionMatrix)<-states
rownames(transitionMatrix)<-states
library(diagram)
plotmat(transitionMatrix,relsize=0.75)
which results in the following plot:
How can I rotate it 90 degrees clockwise, and adjust the self-directed circular arrows so that they are on the midline axis of the plot, opposite from each other instead of being partially on the side as they currently are?
Upvotes: 0
Views: 135
Reputation: 1243
the circular arrows can be changed by manipulating self.shiftx
and self.shifty
values. The arrow location on the circle is determined by self.arrpos
but, beware, the angles is measured in radians, not degrees. The box labels can be switched by altering the sequence of the states like this: states<-c("sun","rain")
instead of states<-c("rain","sun")
. Still trying to figure out how to rotate the entire plot by 90 degrees.
Upvotes: 0