我正在尝试在 geom_col 图上的每个 Y 变量中创建特定的 X 轴顺序。我找到了具有因子及其水平的解决方案,但它似乎对我不起作用。
这是数据框“df_full”:
df_full<-data.frame(conc=c(NK, 1 µM X, 1 µM, 10 µM,100 µM,
NK, 1 µM X, 1 µM, 10 µM,100 µM,
NK, 1 µM X, 1 µM, 10 µM,100 µM),
mean=c( 0.9008428,0.8278645,0.7890388,0.9541905, 0.8537885, 0.8212504,1.3828724,0.7165685, 0.7985398, 1.124524, 0.744428,0.835645,0.562878,0.476905, 0.632885),
Treatment=c("A","A","A","A","A", "B", "B", "B","B","B","C","C","C","C", "C"),
upper =c(1.0990144, 0.9505348, 0.8273494, 1.0389074, 0.9227461,
0.9657371, 1.6864420, 0.7401891, 0.9046951, 1.0990144,
0.9505348, 0.8273494, 1.0389074,0.7401891, 0.9046951),
lower=c(0.7026713, 0.7051941, 0.7507282, 0.9528077, 0.7848309,
0.6767638, 1.0793029, 0.6929479, 0.6923846, 0.7051941,
0.6767638, 1.0793029, 0.6929479, 0.7051941, 0.7507282),
p.value=c(0.0003, 0.6500, 1,0.02,0.0400,
0.3301,0.100,0.023, 0.05, 0.05,
0.0002, 0.86, 0.46, 0.021, 0.001))
我做了一个 conc 变量作为因子,然后它确实只为药物制作了两列(附图 1)。如果我不将 conc 设置为因素,我将无法获得我编码的正确顺序conc_factor
(附图 2)
我当前的ggplot代码:
legend_title <- "conc"
breaks_y =c(0, 0.25, 0.5, 0.75, 1, 1.25, 1.5)
df_full$Label <- NA
df_full$Label[df_full$p.value<0.001]<-'***'
df_full$Label[df_full$p.value<0.01 & is.na(df_full$Label)]<-'**'
df_full$Label[df_full$p.value<0.05 & is.na(df_full$Label)]<-'*'
conc_factor = factor(df_full$conc, levels=c("NK", "10 μM X", "1 μM", "10 μM", "100 μM"))
plot <-
ggplot(df_full, aes(x = factor(Treatment), y = mean, fill = conc_factor)) +
geom_col(color = "black", position = position_dodge(0.8), width = 0.7) +
geom_errorbar(aes(ymax = upper, ymin = lower), width = 0.27, position = position_dodge(0.8), color = "black", size = 0.7) +
geom_text(aes(label = Label, group = conc_factor),size = 3.7, position = position_dodge(width =0.8), color = "black", vjust =-1.8) +
labs(x = "drug", y = "OD", title = "viability", color = "conc", fill = "conc") +
scale_y_continuous(limits = c(0, 1.5), breaks = breaks_y) +
theme_bw() +
theme(axis.text = element_text(size = 12, face = "bold"),
axis.title.y = element_text(size = 12, face ="bold"),
axis.title.x = element_text(size = 12, face ="bold"))
plot + scale_fill_manual(values = wes_palette("Darjeeling1", n = 5))
如何在 geom_col 中的每个 Y 变量中设置特定的“NK”、“10 μM X”、“1 μM”、“10 μM”、“100 μM”X 轴级别?
编辑
我用我当前的代码将 μ 更改为编码版本 \U00B5 解决了这个问题