我正在从另一个论坛(https://www.biostars.org/p/268514/#268559)发帖,我得到了有用的评论,但仍然对ggplot2的输出感到困惑。
我试图在圆圈上得到一个简单的黑色轮廓,但我的代码现在给出了我的随机颜色,似乎忽略了我的scale_colour_manual(values = cols)参数。当我运行以下代码时:
# creating color palette
> cols <- c("red" = "red", "orange" = "orange", "nonsignificant" = "darkgrey", "Increased" = "#00B2FF", "Decreased" = "#00B2FF")
# Make a basic ggplot2 object
> vol <- ggplot(data, aes(x = lfc, y = pval, color = color, labels=gene))
# inserting mnaual colors as per color pallette with term "scale_colour_manual(values = cols)" below
> vol +
ggtitle(label = "Volcano Plot", subtitle = "Colored by fold-change direction") +
geom_point(size = 2.5, alpha = 1, na.rm = T) +
scale_colour_manual(values = cols) +
theme_bw(base_size = 14) +
theme(legend.position = "right") +
xlab(expression(log[2]("VitD" / "Carrier"))) +
ylab(expression(-log[10]("FDR"))) + # Change Y-Axis label
geom_hline(yintercept = 1, colour="#990000", linetype="dashed") + geom_vline(xintercept = 0.586, colour="#990000", linetype="dashed") + geom_vline(xintercept = -0.586, colour="#990000", linetype="dashed") +
scale_y_continuous(trans = "log1p")
我用我定义的调色板得到一张漂亮的图表:
接下来,我想为点添加边框,因此我只更改了2段代码。在开始时,我使用“fill = color”而不是“color = color”来制作基本ggplot
对象
> vol <- ggplot(data, aes(x = lfc, y = pval, fill = color, labels=gene))
我将“shape = 21,color =”black“”添加到“geom_point”参数中:
> vol +
ggtitle(label = "Volcano Plot", subtitle = "Colored by fold-change direction") +
geom_point(size = 2.5, alpha = 1, na.rm = T, shape = 21, colour = "black") +
scale_colour_manual(values = cols) +
theme_bw(base_size = 14) +
theme(legend.position = "right") +
xlab(expression(log[2]("VitD" / "Carrier"))) +
ylab(expression(-log[10]("FDR"))) + l
geom_hline(yintercept = 1, colour="#990000", linetype="dashed") + geom_vline(xintercept = 0.586, colour="#990000", linetype="dashed") + geom_vline(xintercept = -0.586, colour="#990000", linetype="dashed") +
scale_y_continuous(trans = "log1p")
突然间,我有一个似乎随机选择的5种颜色的情节;如果我打印颜色:
print(cols)
red orange nonsignificant Increased Decreased
"red" "orange" "darkgrey" "#00B2FF" "#00B2FF"
调色板仍在那里。