[英]Overlaying jittered points on boxplot conditioned by a factor using ggplot2
[英]different shapes for jittered points in box plots using R and ggplot2
我有一个盒子 plot,其中包含如下所示的抖动数据点。 x-axis
具有三个不同y-axis
具有薪水。
我用下面这段代码给plot。
ggplot(df1, aes(x = Region, y = Income, fill = Sex, color = Sex), size = 10) + geom_boxplot(outlier.shape = NA)+ geom_point(position = position_jitterdodge(0.5), alpha=0.3)
我想做的另一件事是根据不同的种族为数据点添加不同的形状。 例如,男性和女性都被分为caucasian
和african-american
群体。 我的 data.table 中有一个Ethnicity
列。我想在 plot 中将对应于caucasian
人到三角形和african-american
的数据点做成圆圈。
data.table 看起来像这样
Region Income Sex Ethnicity
<chr> <dbl> <chr> <chr>
1 Area1 2000 male African-american
2 Area1 3000 female African-american
3 Area1 2000 male African-american
4 Area1 4000 male African-american
5 Area1 40050 female African-american
6 Area1 60000 male African-american
7 Area1 2000 male Caucasian
8 Area1 4562 female Caucasian
9 Area1 4568 male Caucasian
10 Area1 6573 male Caucasian
我只是想知道是否可以在盒子 plot 中使用。我只是尝试了以下内容,但它不起作用。
ggplot(df1, aes(x = Region, y = Income, fill = Sex, color = Sex, shape = Ethnicity), size = 10)
我将不胜感激任何帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.