我是从另一个论坛(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条代码。首先,我ggplot
用“ fill = color”代替“ color = color”来制作基本对象
> vol <- ggplot(data, aes(x = lfc, y = pval, fill = color, labels=gene))
然后在“ geom_point”参数中添加“ shape = 21,color =“ black””:
> 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"
调色板仍然在那里。
更改color = cols
为时fill = cols
,还应该更改scale_color_manual(...)
为scale_fill_manual(...)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句