我是否可以使用ggplot2或任何其他绘图方法中的以下代码来再现下面所示的绘图?如何显示数据点/样本来反映组变量和基因"OXC"的表达水平?谢谢!
dad <- data.frame(OYC = rnorm(50),
OXC = rnorm(50),
FG = runif(50, min = 60, max = 300),
GTT = runif(50, min= 0, max = 20),
group = rep(c("Aaa", "Bbb", "Ccc", "Ddd"), time = c(15, 12, 8,15)))
row.names(dad) <- paste("sample_", 1:50)
library(ggplot2)
dad %>%
ggplot(aes(x=FG, y= GTT, Color = OXC)) +
geom_point() +
theme(axis.title=element_text(size = 12,face="bold", colour = "blue"),
axis.text = element_text(size = 12),
title=element_text(size= 12,face="bold"))+
labs(y= "ggt", x = "FG")

发布于 2020-09-20 15:07:08
你是说像这样的事吗?我使用了你分享的数据。关键是在您的shape中使用aes()美学元素。它将创造形状,而不是共同点。之后,如果您想要更多的自定义,您可以使用scale_shape_manual()来定义不同的形状。这是somo给你的选项。数字色彩标度也可以添加color或fill美学元素。在这里,代码:
library(ggplot2)
library(dplyr)
#Plot
dad %>%
ggplot(aes(x=FG, y= GTT, color = OXC, shape=factor(group))) +
geom_point() +
theme(axis.title=element_text(size = 12,face="bold", colour = "blue"),
axis.text = element_text(size = 12),
title=element_text(size= 12,face="bold"))+
labs(y= "ggt", x = "FG")输出:

如果您想设置不同的颜色,可以使用以下内容:
#Plot 2
dad %>%
ggplot(aes(x=FG, y= GTT, color = OXC, shape=factor(group))) +
geom_point() +
theme(axis.title=element_text(size = 12,face="bold", colour = "blue"),
axis.text = element_text(size = 12),
title=element_text(size= 12,face="bold"))+
labs(y= "ggt", x = "FG")+
scale_color_gradient2(low = 'red',mid = 'green',high = 'yellow')输出:

还有几个层次的定制:
#Plot 3
dad %>%
ggplot(aes(x=FG, y= GTT, color = OXC, shape=factor(group))) +
geom_point(size=3) +
theme(axis.title=element_text(size = 12,face="bold", colour = "blue"),
axis.text = element_text(size = 12),
title=element_text(size= 12,face="bold"))+
labs(y= "ggt", x = "FG")+
scale_shape_manual(values = c('circle','square','triangle','diamond'))+
scale_color_gradient2(low = 'red',mid = 'yellow',high = 'blue')输出:

发布于 2020-09-20 15:23:05
这是一个让你接近你的例子的情节(形状周围的黑线,分散的蓝色/红色比例)。您没有在原始代码中获得颜色,因为颜色美学是color而不是Color。使用scale_shape_manual,您可以选择具有坚实的轮廓和填充的形状。然后将颜色变量分配给fill以填充这些形状。使用scale_fill_gradient2,您可以定义一个发散的比例
dad %>%
ggplot(aes(x=FG, y= GTT, fill = OXC, shape = group)) +
geom_point(size = 5) +
theme(axis.title=element_text(size = 12,face="bold", colour = "blue"),
axis.text = element_text(size = 12),
title=element_text(size= 12,face="bold"))+
scale_shape_manual(values = c("Aaa" = 21, "Bbb" = 22, "Ccc" = 23, "Ddd" = 24)) +
scale_fill_gradient2(low = "red", mid = "white", high = "blue") +
labs(y= "ggt", x = "FG")

https://stackoverflow.com/questions/63980346
复制相似问题