[英]How can I add text labels showing the amount of data points in a geom_jitter plot?
我有一个 geom_jitter 图,在 x 轴上有一个分类变量,在 y 轴上有一个连续变量。 我想在每个 x 轴类别的最大值之上绘制该类别中包含的数据点总数,这基本上是绘制输出
table(my_df$my_categorical_var)
到目前为止,我已经尝试过:
+geom_text(aes(x= my_categorical_var), y= max(my_continuous_var), label=as.vector(my_df$my_categorical_var))
但这会输出一个错误:
Error in `geom_text()`:
! Problem while computing aesthetics.
ℹ Error occurred in the 2nd layer.
Caused by error in `check_aesthetics()`:
! Aesthetics must be either length 1 or the same as the data
(20996)
✖ Fix the following mappings: `label`
这基本上让您为每个标签创建一个 geom_text 或修改数据框并为每个类别添加一个新列,其中包含我要绘制的数字。 然而,可能还有更直接的东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.