sort won't work with my mosaicplot

I have this graph created with the code:

mosaicplot(table(Vowel, Jacc$Jacc), 
           color = blues9,
           main = "Japanese Knowledge and Accuracy compared to Vowel Features")

However, I wanted to reorganize the columns so that they would be sorted by long-short pairs instead of by alphabetical. My first attempt at code for it looked like this:

mosaicplot(table(Vowel, Jacc$Jacc), 
  color = blues9,
  main = "Japanese Knowledge and Accuracy compared to Vowel Features",
  sort = "long-a", "short-a", "long-i", "short-i", "long-o", "short-o", "long-u", "short-u")

Vowel is a name for what refers to Quality and Length of vowels (short-a, long-a, short-i, long-i, etc etc) within the Jacc data set, and Jacc refers to knowledge of Japanese + accuracy.

the error I get is:

Error in -rev(shade) : invalid argument to unary operator

I asked a professor and got a suggestion to try this code:

mosaicplot(table(Vowel, Jacc$Jacc), 
           color = blues9,
           main = "Japanese Knowledge and Accuracy compared to Vowel Features",
           sort = c("long-a", "short-a", "long-i", "short-i", "long-o", "short-o", "long-u", "short-u”))

however now i get a very strange error that, as far as I can tell is due to r studio parsing this as starting with the sort as the head of the command?

+ mosaicplot(table(Vowel, Jacc$Jacc), 
+            color = blues9,
+            main = "Japanese Knowledge and Accuracy compared to Vowel Features",
Error: unexpected symbol in:
"           color = blues9,
           main = "Japanese"
>            sort = c("long-a", "short-a", "long-i", "short-i", "long-o", "short-o", "long-u", "short-u”))

Does anyone have clues as to how to fix this?

hi @cupricfae

Your error come from a strange quote you put at the end off your code (after short-u). Instead of ..., "short-u” put ..., "short-u".

Now if you want us to test your code, you must put a minimal reprex dataset that we can use. see here:

Hope it help

1 Like

Hi,

I don't know if this is an error when parsing your code here on the forum, but the very last quotation character you use is not a correct one

"short-u”

This usually happens when you copy code from other sources like word documents that use different quotation characters that are not recognized by R and generate the error. Just replace the quotations with the normal one used in R by removing it and typing " again.

Hope this helps,
PJ

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