7

I made a scatterplot with ggplot2 and I mapped a binary variable to point size. The result was satisfactory but I got the warning "Using size for a discrete variable is not advised".

I understand that using size to map a non ordinal categorical variable with several levels may be less clear than using point shape or different colors. However, I wonder whether that warning is intended to warn us about anything more serious.

Is there a more advisable way to change point size according to a binary or categorical variable than using aes(size=...)?

Is the warning "Using size for a discrete variable is not advised" just a design tip?

If my result looks good, should I worry about that warning next time I want the same kind of graphic on similar data?

Pere
  • 706
  • 1
  • 7
  • 21
  • 4
    I view it as a design tip to be broken when necessary – Richard Telford May 07 '18 at 10:47
  • 3
    I think you've already mentioned it. Using size to map a non-ordinal categorical variable may suggest an ordinal relationship to the viewer, when none was intended. I find that's quite serious as it could result in miscommunication, but your mileage may vary. – Z.Lin May 07 '18 at 13:03
  • 4
    I think that if you truly want to map categories to size, you should convert the categories to numbers and then do the mapping. That avoids the warning and ensures that the mapping happens exactly the way you want it to. – Claus Wilke May 08 '18 at 03:21
  • I feel like this warning is paternalistic and preachey. It has no place in a code warning, it is a style recommendation. Like all style recommendations there are times where it's valid to break it, and then I don't appreciate being warned at. – Simon Woodward Mar 09 '23 at 19:13

2 Answers2

4

As the comments and you have mentioned, if you use size for categorical variables, then you mislead the reader.

If you have numbers and have this error, convert them with as.numeric(), as they may have been stored as factors or character values. That will sort out the legend too.

Peter
  • 225
  • 3
  • 8
3

The reason for this Warning is that size is an ordered aesthetic, and you are mapping an unordered variable to an ordered aesthetic (size) which is not a good idea. Try using ordered = T in your as.factor() or factor() function while you are building your variable, and that fixes this issue. You can also use ordered() function instead of factor().

ah bon
  • 9,293
  • 12
  • 65
  • 148
Farhad
  • 151
  • 7