gpt4 book ai didi

r - 如何通过点类型区分 geom_point 图中的组

转载 作者:行者123 更新时间:2023-12-04 07:34:21 25 4
gpt4 key购买 nike

我有一个数据框,它有两种不同的样本类型(A 和 B)。我想通过使用不同的 shape 来区分这些选项。这是一个数据框和我目前执行此操作的尝试。
dput(head(df)) 的输出

structure(list(Mean.Count = c(30404.8407153174, 15689.4221807262, 30404.8407153174, 15689.4221807262), 
Log2FC = c(-0.00357013689574257, -0.00417251481039714, 0.306809506669248, 0.224653107007472),
Adj.P.Value = c(0.988865360408676, 0.981816989495127, 0.00202882891738576,
2.72576774009609e-05),
TimeKD = c("A", "A", "B", "B"),
Gene = c("HSPA5","MYH9", "HSPA5", "MYH9")),
row.names = c("HSPA5", "MYH9", "HSPA51", "MYH91"),
class = "data.frame")
当前尝试
ggplot(df, aes(x = Gene, y = Log2FC, group=TimeKD)) + 
geom_point(aes(color = -Adj.P.Value, size = Mean.Count), alpha = 0.5)+
coord_flip() +
scale_colour_gradientn(
colours = grDevices::colorRampPalette(c("black", "cyan", "violet"))(n = 200),
values = NULL,
space = "Lab",
na.value = "grey50",
guide = "colourbar",
aesthetics = "colour"
)
enter image description here
目前 A 和 B 样本都是圆形。我可以用 ggplot2将其中一个变成另一种形状?
任何帮助,将不胜感激。

最佳答案

您可以添加 shape = TimeKDaesgeom_point像这样打电话...

ggplot(df, aes(x = Gene, y = Log2FC, group=TimeKD)) + 
geom_point(aes(color = -Adj.P.Value,
size = Mean.Count,
shape = TimeKD), # <-- Right here!
alpha = 0.5)+
coord_flip() +
scale_colour_gradientn(
colours = grDevices::colorRampPalette(c("black", "cyan", "violet"))(n = 200),
values = NULL,
space = "Lab",
na.value = "grey50",
guide = "colourbar",
aesthetics = "colour"
)
看起来像这样......
the requested graph with different shapes for the groups

关于r - 如何通过点类型区分 geom_point 图中的组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67806815/

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