Difference between passing options in aes() and outside of it in ggplot2

后端 未结 1 1410
北荒
北荒 2020-11-28 09:22

After fiddling with point size options in ggplot2, I noticed examples in which size was passed both inside and outside the aes() parameter of geom_point()

相关标签:
1条回答
  • 2020-11-28 10:03

    When specified inside aes, an aesthetic is mapped to the value of a variable in the data. Since there is a mapping between the data and the visible aesthetic, there is a legend which shows that mapping. Outside of an aes call, the aesthetic is just set to a specific value. In the examples you show, the size (and colour) are set to the same value for all points. In this case, there is no need for a legend because the size (or colour) does not convey any meaning (with regard to the underlying data).

    The issue you are seeing with the legend is due to the size being mapped to a continuous variable. It happens that there are only two values that this variable takes on in your data, but in principle, a continuous variable could take on any value. If it really is just a choice-of-two variable, make it a factor (either in the original data or in the aesthetic call aes(size=factor(qsec)).

    0 讨论(0)
提交回复
热议问题