'How to plot interactions of predictors when the response data is ordinal in r?

I have a dataset with an ordinal target variable. I need to draw an interaction plot of one continuous and one categorical value to see if their interaction matters.

Here, I will use diamonds built-in dataset for reproducibility. Let's pretend that "cut" is a target variable. I tried to use this:

interaction.plot(diamonds$carat, diamonds$clarity, diamonds$cut)

which gives me this error:

Error in plot.window(...) : need finite 'ylim' values

It works for continuous target variables. But my data has an ordinal response variable. Should I recode my target variable for this function or is there a better way of plotting it?

The plot should look like this (https://www.statology.org/interaction-plot-r/):

enter image description here

r


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source