gpt4 book ai didi

r - ggplot2 绘制黑色轮廓

转载 作者:行者123 更新时间:2023-12-04 09:32:33 25 4
gpt4 key购买 nike

我从另一个论坛 (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")

我用我定义的调色板得到了一张漂亮的图表:

Color volcano plot

接下来,我想为点添加边框,所以我只更改了 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"

调色板还在。

最佳答案

当您将 color = cols 更改为 fill = cols 时,您还应该将 scale_color_manual(...) 更改为 scale_fill_manual (...)

关于r - ggplot2 绘制黑色轮廓,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45805376/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com