Problem with bar plot

Hi, I'd appreciate some help with an issue I'm having. When creating a bar plot using the following:
barplot(table(Mydata$MsType, Mydata$Rel1yPre), ylim=c(0,90),
col=c("navyblue", "seagreen", "tomato3"),
xlab="Number of Relapses 1y Pre diagnosis",
ylab="Frequency",
main="Type of MS vs. Number of Relapses 1 year prior to Diagnosis",
legend.text=c("PPMS", "RRMS", "SPMS"),
beside=TRUE)

I've realised that for some reason the value of the variables is assigned depending on the order I put it in, which results in incorrect data being shown on the plot. For example, if I put "RRMS", "PPMS", "SPMS" (instead of the above) the plot simply changes the colours and incorrectly shows the frequency of RRMS as belonging to PPMS. I've only noticed because I know my data and I'm worried im getting incorrect plots!
I'm clearly doing something wrong - I'm still a beginner so I'd appreciate it if someone could guide me as to what the issue is.
Thanks!

Thank you for your reply! I'm not sure whether I understood you correctly, do you mean saving as a table first?
is this what you mean?:
relapses<-table(Mydata$MsType, Mydata$Rel1yPre)
barplot(relapses, main="Type of MS vs. Number of Relapses 1 year prior to Diagnosis", col=c("navyblue", "seagreen", "tomato3"),
legend=rownames(relapses))

thanks

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.