问题描述
我是 R 的新手,我正在尝试根据具有 3 列的数据框生成图:
基因 (Character
)、表达 (Boolean
)、功能 (Levels
)
对于每个基因我想生成由表达(0=circle,1= square
)指定的形状并根据功能为形状着色(即每个级别的不同颜色)
谁能推荐一种方法来做到这一点?
解决方法
我会盲目刺杀:
set.seed(4)
eg <- data.frame(Gene = paste("Gene",LETTERS[1:4]),Expressed = sample(0:1,size=4,replace=TRUE),Function = paste0("F",1:4))
eg
# Gene Expressed Function
# 1 Gene A 1 F1
# 2 Gene B 0 F2
# 3 Gene C 0 F3
# 4 Gene D 0 F4
library(ggplot2)
ggplot(eg,aes(Gene,y=1)) +
geom_point(aes(shape=factor(Expressed),colour=Function),size=4) +
scale_shape_manual(values = c("0"="circle","1"="square"))