我正在用正负数据做箱线图,并希望轴位于 y=0。之后添加一条线并不优雅,因为这条线会在盒子上而不是在盒子后面。(目标是使 y=0 处的线为黑色,而 1 和 -1 处的线应为灰色)
另外我想只有轴线。因此我使用
axis.line=element_line()
,panel.border = element_blank()
在主题中。但是垂直线高于 1,这看起来不太好(我的数据根据定义在 -1 和 1 之间)。
这是代码:
require (ggplot2)
theme_jack <- function (base_size = 10, base_family = "") {
theme_bw(base_size = base_size, base_family = base_family) %+replace%
theme(
title = element_text(size = 12)
,axis.title.x = element_text(colour = "white", size=0)
,axis.title.y = element_text(size=12, angle=90)
,axis.text.x=element_text(size=8)
,panel.grid.major = element_line(colour = "grey")#,
,axis.line=element_line()
,panel.border = element_blank()
,panel.grid.minor = element_blank()
,panel.grid.major.x = element_blank()
,legend.position = "none"
)
}
theme_set(theme_jack())
datatest2=structure(list(datatest2.genotype = structure(c(1L, 1L, 5L, 5L,
1L, 5L, 5L, 5L, 1L, 5L, 1L, 5L, 1L, 5L, 5L, 1L, 1L, 1L, 5L, 5L,
1L, 1L, 1L, 5L, 1L, 1L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L), .Label = c("CS_d42-chG80", "CS_G_c380cha", "CS_Gd42-chG80",
"PKC_CS", "PKC_d42-chG80", "PKC_G_c380cha", "PKC_Gd42-chG80"), class = "factor"),
datatest2.score = c(0.8882, -0.3775, -0.4053, 0.1962, 0.9982,
0.5627, -0.4865, 0.7267, 0.3276, 0.5017, 0.9731, 0.1525,
0.7857, 0.6121, 0.8508, 0.1311, -0.2457, 0.8848, -0.1254,
0.1047, -0.2715, 0.7189, 0.4115, 0.9704, -0.8328, -0.1301,
0.9756, 0.2317, 0.4297, 0.9967, 0.6423, 0.8516, 0.3386, 0.5208,
0.9148, 0.2539, 0.8581, 0.5621, 0.5969, 0.7435)), .Names = c("genotype",
"score"), row.names = c(NA, 40L), class = "data.frame")
p=ggplot(datatest2, aes(x=factor(genotype),y= score))
plot=p+ geom_boxplot()+ labs(x="genotype",y="PI during final test")+
scale_fill_grey(start = 0.9, end = 0.9)+ ##allow good bw prints
scale_y_continuous(minor_breaks=NULL,breaks = seq(-1 , 1, 1) )
plot