r - 如何预先制作如下图?
问题描述
我可以使用 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")
解决方案
你的意思是这样的吗?我已经使用了您分享的数据。关键是shape
在你的aes()
. 它将创建形状而不是公共点。之后,如果您想要额外的自定义,您可以使用scale_shape_manual()
以定义不同的形状。这里为您提供一些选择。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')
输出:
推荐阅读
- javac - Java 类型推断失败:
不是功能接口 - c# - 如何在 C# 中将文件/文件路径从一个 Button_Click 事件传递到另一个事件?
- javascript - 收藏夹的本地存储列表
- php - 文章标题在 foreach 循环中多次显示
- spring-boot - Spring Data Rest 模块 2.1.3 和 Swagger 2.9.2 导致问题
- java - Java将带有文件和结构的子目录移动到父目录
- jquery - 将元素悬停在其他元素上
- ajax - KeyCloak 在 HTTP OPTIONS 请求上返回 HTTP 204
- office-ui-fabric - 为什么复选框文本不使用主题字体大小?
- python - python中的回调字典