我正在尝试制作各种散点图,其中符号形状和符号填充由两个不同的变量设置。这是我的数据示例:
Sample Experiment Replicate EPS Time Group
1 1 1 5 24 Wild-type
2 1 3 4.5 24 Wild-type
3 2 2 2 24 Wild-type
4 1 2 6 24 Variant
5 2 1 4 24 Variant
6 1 2 3 48 Wild-type
7 1 3 2.5 48 Wild-type
8 2 3 3.5 48 Wild-type
9 1 2 3.5 48 Variant
10 2 2 6.5 48 Variant
11 1 1 3 72 Wild-type
12 2 3 3.5 72 Wild-type
13 1 3 9.5 72 Variant
14 2 3 12.5 72 Variant
这是我正在使用的代码。一切正常,除了没有填写我的任何符号:
fig.one<-read.table(file='data/Figure1.txt', header=TRUE)
fig.one$time.cat[fig.one$Time == 24] <- 2.5
fig.one$time.cat[fig.one$Time == 48] <- 6
fig.one$time.cat[fig.one$Time == 72] <- 9.5
fig.one$scat.adj[fig.one$Group=='Wild-type']<- -0.50
fig.one$scat.adj[fig.one$Group=='Variant']<- 0.50
my.pch<-c(21,24)
my.bg<-c('black','white')
ggplot(fig.one, aes(time.cat, EPS, shape=my.pch[Experiment]),fill=my.bg[factor(Group)]) +
geom_jitter(aes(time.cat + scat.adj,EPS),
position=position_jitter(width=0.2,height=0),
alpha=0.6,
size=3) +
scale_fill_identity() +
scale_shape_identity() +
scale_x_continuous("Time since inoculation (hours)", breaks=c(2.5,6,9.5),labels=c( "24", "48", "72"), limits=c(1,11)) +
ylab("EPS (grams per litre)") +
theme(axis.text=element_text(size=12, face='bold'),
axis.title=element_text(size=14, face='bold'),
panel.grid.major = element_blank(), panel.grid.minor = element_blank())
一如既往地感谢您的帮助!