Reorder plot variables

Hi guys,

Having a little difficulty reordering my X-Axis for a logistic mixed effects regression. I know how to do it with the regular plot() command, but with the model I am using, that doesn't work. Here is minimal code which should be sufficient to get the jist of what I'm doing. Voice = IV, probability = DV, question = fixed effect, participant = random effect.

model = lmer(probability ~ Voice + question +(1|participant), data=finalasian, family="binomial")

From this model, I then produce this graph:

plotLMER.fnc(model, pred="Voice", xlabel = "Speaker Voice", ylabel = "Probability of support", cex = 0.8)

The IVs (voices) are returned in alphabetical order on the x axis. I would like to specify what order they appear in.

Please ask for more code as you need it, and thanks in advance for any pointers




Ambassador to the humans
Can you provide a minimal dataset that illustrates your problem? My guess as to a solution would be to make Voice a factor and make sure the levels are in the order you want.
Sure thing Dason: I'll go with the kitchen sink approach this time (annotated with my comments), and see if that helps at all.

#read in the data

data = read.csv('allresultscodedbinaryx.csv')

# get out the data to do with asian

pleasant = data$pleasant
immigrant = data$immigrant
englishofficial = data$english.official
culture = data$culture
equalaccess = data$equal.access

pl = rep('pleasant', 245)
im = rep('immigrant', 245)
eng = rep('englishofficial', 245)
cul = rep('culture', 245)
eq = rep('equalaccess', 245)

# create the tables that have participant, question, and response

a= cbind(part, pl, pleasant)
b= cbind(part, im, immigrant)
c= cbind(part, eng, englishofficial)
d= cbind(part, cul, culture)
e= cbind(part, eq, equalaccess)

#rename the columns so they have the same names

colnames(a) <- c("participant","question", "response")
colnames(b) <- c("participant","question", "response")
colnames(c) <- c("participant","question", "response")
colnames(d) <- c("participant","question", "response")
colnames(e) <- c("participant","question", "response")

# create the core data set.

asiandata = rbind(a,b,c,d,e)

#add participant info
participants = read.csv("participants.csv")

asiandatawithpart = merge(asiandata, participants, by.x="participant", by.y="participant", x.all=T)

#recode to supportive/nonsupportive
qr = paste(asiandatawithpart$question, asiandatawithpart$response, sep=".")
asiandatawithpart$qr = qr
asianrecode = read.csv("asianrecode.csv")
#re-code for age and new file
#the end
finalasian = merge(asiandatawithpart, asianrecode, by.x="qr", by.y="qr", x.all=T)
finalasian$Sex = as.factor(finalasian$Sex)
finalasian$Ethnicity = as.factor(finalasian$Ethnicity)


Ambassador to the humans
Huh. Surprising how little that helped.

I don't have those csvs so I can't reproduce that. Anywho did my suggestion of releveling voice as a factor work?


Probably A Mammal
It really depends on what that special plotting function is doing. Since it takes the model object, I would assume it's using something like it's model.frame to create the graph. Unless they design the function with the ability to alter something like that, my guess is you'll have to either (1) create the function yourself or (2) tweak the input to get the result you want. For instance, if you send it an adjusted model.frame object, it might still plot it. There's also Dason's point about the levels of your factor. Factors are by default ordered alphabetically. Therefore, if you explicitly set the order of your levels, you might gain control that way if that is how the ordering of your x-axis is determined. Be careful, though, that your levels match your data after you adjust them.


New Member
Dason - thanks, setting voice as a factor worked. Just taken me a few days to get it right (in amongst other things).

Thanks again