Here is some code to generate a 0th order Markov Chain plot. I'd like to replace the plot's x-axis labels (c, d, h, i, o, p) with 45 degree rotated labels showing the first six months of the year. However, using xaxt="n"
in the plot
call doesn't seem to work. This code just writes over the existing labels, rather than replacing them. How can I replace the labels with the ones I want?
library(clickstream)
clickstreams <- c("User1,h,c,c,p,c,h,c,p,p,c,p,p,o",
"User2,i,c,i,c,c,c,d",
"User3,h,i,c,i,c,p,c,c,p,c,c,i,d",
"User4,c,c,p,c,d",
"User5,h,c,c,p,p,c,p,p,p,i,p,o",
"User6,i,h,c,c,p,p,c,p,c,d")
csf <- tempfile()
writeLines(clickstreams, csf)
cls <- readClickstreams(csf, header = TRUE)
mc <- fitMarkovChain(cls, order=0)
plot(mc, xaxt="n")
text(x=1:6, y=par()$usr[3], labels = month.name[1:6], srt=45, adj = c(1.1,1.1), xpd = TRUE, cex=.9)
str(mc)
reveals the structure of the S4 object. Passing intoplot
just the xy-coordinates rather than the whole"MarkovChain"
object recovers thexaxt
option functionality. Usingwith
makes this most convenient.Moreover this allows us to use the implemented S4
plot
method for signature'MarkovChain'
of theclickstream
package.Result
Data