我想改变 geom_boxplot()
中线的颜色.我已经看过了,但找不到办法。我已经在这里发布了我正在使用的 R 代码,但我真的需要一个关于如何更改颜色的引用。
ggplot(invitro2) +
geom_boxplot(aes(x = reorder(CANCER_TYPE,tmedian), y = GeoMedian_IC50)) +
xlab("") +
geom_point(aes(x = reorder(CANCER_TYPE,tmedian), y = GeoMedian_IC50)) +
theme_bw() +
scale_y_log10(breaks = trans_breaks("log10", function(x) 10^x),
labels = trans_format("log10", math_format(10^.x))) +
annotation_logticks(sides="l") +
theme(axis.text.x=element_text(angle=45,size=10,hjust=1),
panel.grid.major = element_blank())
最佳答案
您可以使用绘图的细节,推导出中线所在位置的坐标,然后使用 geom_segment
为其添加颜色。 .
library(ggplot2)
p <- ggplot(mtcars, aes(factor(am), mpg)) + geom_boxplot()
dat <- ggplot_build(p)$data[[1]]
p + geom_segment(data=dat, aes(x=xmin, xend=xmax,
y=middle, yend=middle), colour="red", size=2)
还得加size
的线,以便它覆盖原来的黑色中位数线
关于r - 更改颜色中线 ggplot geom_boxplot(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30002257/